Labels and Selectors

Labels are key/value pairs that are attached to Kubernetes objects, such as pods (this is usually done indirectly via deployments). Labels are intended to be used to specify identifying attributes of objects that are meaningful and relevant to users. Labels can be used to organize and to select subsets of objects. See Labels and Selectors in the Kubernetes documentation for more information.

The following Kubernetes labels have a defined meaning in our Zalando context:

application
Application ID as defined in our Kio application registry. Example: “zmon-controller”
version
User-defined application version. This is used as input for the CI/CD pipeline and usually references a Docker image tag. Example: “cd53”
release
Incrementing release counter. This is generated by the CI/CD pipeline and is used for traffic switching. Example value: “4”
stage
Deployment stage to allow canary deployments. Allowed values are “canary” and “production”.
owner
Owner of the Kubernetes resource. This needs to reference a valid organizational entity in the context of the cluster’s business partner. Example value: “team/eagleeye”

Some labels are required for every deployment resource:

  • application
  • version
  • release
  • stage

Example deployment metadata:

metadata:
  labels:
    application: my-app
    version: "v31"
    release: "r42"
    stage: production

Kubernetes services will usually select only on application and stage:

kind: Service
apiVersion: v1
metadata:
  name: my-app
spec:
  selector:
    application: my-app
    stage: production
  ports:
    - port: 80
      targetPort: 8080
      protocol: TCP

You can always define additional custom labels as long as they don’t conflict with the above label catalog.