Recommended Labels

    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: . Labels without a prefix are private to users. The shared prefix ensures that shared labels do not interfere with custom user labels.

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

    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-abcxzy. This enables the application and instance of the application to be identifiable. Every instance of an application must have a unique name.

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

    Consider the case for a simple stateless service deployed using Deployment and 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. ...

    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-abcxzy
    7. app.kubernetes.io/version: "4.9.4"
    8. app.kubernetes.io/component: server
    9. ...

    The Service is used to expose WordPress:

    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-abcxzy
    7. app.kubernetes.io/version: "5.7.21"
    8. app.kubernetes.io/managed-by: helm
    9. app.kubernetes.io/component: database
    10. ...

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