Recommended Labels

You can visualize and manage Kubernetes objects with more tools than kubectl and the dashboard. A common set of labels allows tools to work interoperably, describing objects in a common manner that all tools can understand.

In addition to supporting tooling, the recommended labels describe applications in a way that can be queried.

The metadata is organized around the concept of an application. Kubernetes is not a platform as a service (PaaS) and doesn’t have or enforce a formal notion of an application. Instead, applications are informal and described with metadata. The definition of what an application contains is loose.

Note:

These are recommended labels. They make it easier to manage applications but aren’t required for any core tooling.

Shared labels and annotations share a common prefix: app.kubernetes.io. Labels without a prefix are private to users. The shared prefix ensures that shared labels do not interfere with custom user labels.

Labels

In order to take full advantage of using these labels, they should be applied on every resource object.

KeyDescriptionExampleType
app.kubernetes.io/nameThe name of the applicationmysqlstring
app.kubernetes.io/instanceA unique name identifying the instance of an applicationmysql-abcxyzstring
app.kubernetes.io/versionThe current version of the application (e.g., a SemVer 1.0, revision hash, etc.)5.7.21string
app.kubernetes.io/componentThe component within the architecturedatabasestring
app.kubernetes.io/part-ofThe name of a higher level application this one is part ofwordpressstring
app.kubernetes.io/managed-byThe tool being used to manage the operation of an applicationHelmstring

To illustrate these labels in action, consider the following StatefulSet object:

  1. # This is an excerpt
  2. apiVersion: apps/v1
  3. kind: StatefulSet
  4. metadata:
  5. labels:
  6. app.kubernetes.io/name: mysql
  7. app.kubernetes.io/instance: mysql-abcxyz
  8. app.kubernetes.io/version: "5.7.21"
  9. app.kubernetes.io/component: database
  10. app.kubernetes.io/part-of: wordpress
  11. app.kubernetes.io/managed-by: Helm

Applications And Instances Of Applications

An application can be installed one or more times into a Kubernetes cluster and, in some cases, the same namespace. For example, WordPress can be installed more than once where different websites are different installations of WordPress.

The name of an application and the instance name are recorded separately. For example, WordPress has a app.kubernetes.io/name of wordpress while it has an instance name, represented as app.kubernetes.io/instance with a value of wordpress-abcxyz. This enables the application and instance of the application to be identifiable. Every instance of an application must have a unique name.

Examples

To illustrate different ways to use these labels the following examples have varying complexity.

A Simple Stateless Service

Consider the case for a simple stateless service deployed using Deployment and Service objects. The following two snippets represent how the labels could be used in their simplest form.

The Deployment is used to oversee the pods running the application itself.

  1. apiVersion: apps/v1
  2. kind: Deployment
  3. metadata:
  4. labels:
  5. app.kubernetes.io/name: myservice
  6. app.kubernetes.io/instance: myservice-abcxyz
  7. ...

The Service is used to expose the application.

  1. apiVersion: v1
  2. kind: Service
  3. metadata:
  4. labels:
  5. app.kubernetes.io/name: myservice
  6. app.kubernetes.io/instance: myservice-abcxyz
  7. ...

Web Application With A Database

Consider a slightly more complicated application: a web application (WordPress) using a database (MySQL), installed using Helm. The following snippets illustrate the start of objects used to deploy this application.

The start to the following Deployment is used for WordPress:

  1. apiVersion: apps/v1
  2. kind: Deployment
  3. metadata:
  4. labels:
  5. app.kubernetes.io/name: wordpress
  6. app.kubernetes.io/instance: wordpress-abcxyz
  7. app.kubernetes.io/version: "4.9.4"
  8. app.kubernetes.io/managed-by: Helm
  9. app.kubernetes.io/component: server
  10. app.kubernetes.io/part-of: wordpress
  11. ...

The Service is used to expose WordPress:

  1. apiVersion: v1
  2. kind: Service
  3. metadata:
  4. labels:
  5. app.kubernetes.io/name: wordpress
  6. app.kubernetes.io/instance: wordpress-abcxyz
  7. app.kubernetes.io/version: "4.9.4"
  8. app.kubernetes.io/managed-by: Helm
  9. app.kubernetes.io/component: server
  10. app.kubernetes.io/part-of: wordpress
  11. ...

MySQL is exposed as a StatefulSet with metadata for both it and the larger application it belongs to:

  1. apiVersion: apps/v1
  2. kind: StatefulSet
  3. metadata:
  4. labels:
  5. app.kubernetes.io/name: mysql
  6. app.kubernetes.io/instance: mysql-abcxyz
  7. app.kubernetes.io/version: "5.7.21"
  8. app.kubernetes.io/managed-by: Helm
  9. app.kubernetes.io/component: database
  10. app.kubernetes.io/part-of: wordpress
  11. ...

The Service is used to expose MySQL as part of WordPress:

  1. apiVersion: v1
  2. kind: Service
  3. metadata:
  4. labels:
  5. app.kubernetes.io/name: mysql
  6. app.kubernetes.io/instance: mysql-abcxyz
  7. app.kubernetes.io/version: "5.7.21"
  8. app.kubernetes.io/managed-by: Helm
  9. app.kubernetes.io/component: database
  10. app.kubernetes.io/part-of: wordpress
  11. ...

With the MySQL StatefulSet and Service you’ll notice information about both MySQL and WordPress, the broader application, are included.