Recommended Labels

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

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

The metadata is organized around the concept of anapplication. Kubernetes is nota 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 ofwhat an application contains is loose.

Note:

These are recommended labels. They make it easier to manage applicationsbut aren't required for any core tooling.

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

Labels

In order to take full advantage of using these labels, they should be appliedon 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., aSemVer 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 followingStatefulSet object:

# This is an excerptapiVersion:apps/v1kind:StatefulSetmetadata:labels:app.kubernetes.io/name:mysqlapp.kubernetes.io/instance:mysql-abcxyzapp.kubernetes.io/version:"5.7.21"app.kubernetes.io/component:databaseapp.kubernetes.io/part-of:wordpressapp.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 morethan once where different websites are different installations of WordPress.

The name of an application and the instance name are recorded separately. Forexample, WordPress has aapp.kubernetes.io/name ofwordpress while it hasan instance name, represented asapp.kubernetes.io/instance with a value ofwordpress-abcxyz. This enables the application and instance of the applicationto 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 usingDeployment andService objects. The following two snippets represent how the labels could be used in their simplest form.

TheDeployment is used to oversee the pods running the application itself.

apiVersion:apps/v1kind:Deploymentmetadata:labels:app.kubernetes.io/name:myserviceapp.kubernetes.io/instance:myservice-abcxyz...

TheService is used to expose the application.

apiVersion:v1kind:Servicemetadata:labels:app.kubernetes.io/name:myserviceapp.kubernetes.io/instance:myservice-abcxyz...

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 illustratethe start of objects used to deploy this application.

The start to the followingDeployment is used for WordPress:

apiVersion:apps/v1kind:Deploymentmetadata:labels:app.kubernetes.io/name:wordpressapp.kubernetes.io/instance:wordpress-abcxyzapp.kubernetes.io/version:"4.9.4"app.kubernetes.io/managed-by:Helmapp.kubernetes.io/component:serverapp.kubernetes.io/part-of:wordpress...

TheService is used to expose WordPress:

apiVersion:v1kind:Servicemetadata:labels:app.kubernetes.io/name:wordpressapp.kubernetes.io/instance:wordpress-abcxyzapp.kubernetes.io/version:"4.9.4"app.kubernetes.io/managed-by:Helmapp.kubernetes.io/component:serverapp.kubernetes.io/part-of:wordpress...

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

apiVersion:apps/v1kind:StatefulSetmetadata:labels:app.kubernetes.io/name:mysqlapp.kubernetes.io/instance:mysql-abcxyzapp.kubernetes.io/version:"5.7.21"app.kubernetes.io/managed-by:Helmapp.kubernetes.io/component:databaseapp.kubernetes.io/part-of:wordpress...

TheService is used to expose MySQL as part of WordPress:

apiVersion:v1kind:Servicemetadata:labels:app.kubernetes.io/name:mysqlapp.kubernetes.io/instance:mysql-abcxyzapp.kubernetes.io/version:"5.7.21"app.kubernetes.io/managed-by:Helmapp.kubernetes.io/component:databaseapp.kubernetes.io/part-of:wordpress...

With the MySQLStatefulSet andService you'll notice information about both MySQL and WordPress, the broader application, are included.

Last modified April 25, 2024 at 1:16 AM PST:Update common-labels.md (4e973d44ba)