Kubernetes Labels and Annotations: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
(Created page with "=Internal= * Kubernetes Concepts =<span id='Label'></span>Labels= =<span id='Annotation'></span>Annotations=")
 
No edit summary
 
(20 intermediate revisions by the same user not shown)
Line 1: Line 1:
=External=
* https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/
=Internal=
=Internal=
* [[Kubernetes_Concepts#Subjects|Kubernetes Concepts]]
* [[Kubernetes_Concepts#Subjects|Kubernetes Concepts]]
* [[AWS_Tags#Overview|AWS Tags]]
* [[Azure_Tags#Overview|Azure Tags]]
* [[GCP_Labels_and_Tags#Overview|GCP Labels and Tags]]


=Overview=


=<span id='Label'></span>Labels=
=<span id='Label'></span>Labels=
A label is a key/value pair contains identifying information used to organize and categorize (scope and select) objects.
Labels are used by selector queries, or within selector sections of object definitions. [[Kubernetes_Workload_Resources#ReplicaSet|Replicaset controllers]] and [[Kubernetes_Service_Concepts#Service|services]] use selectors to identify the pods that fall under their scope.
Labels is a mechanism to define loose couplings.
The structure of keys and values is constrained, so they can be evaluated quickly.
<font color='darkgray'>TODO:
* https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/
* Label syntax and character set: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#syntax-and-character-set</font>.
For a specific object declaration, the labels are specified in the [[Kubernetes Manifest Metadata#labels|metadata]] section of the [[Kubernetes_Manifests#metadata|manifest]].
=<span id='Annotation'></span>Annotations=
=<span id='Annotation'></span>Annotations=
{{External|https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/}}
An annotation contains non-identifying information. The information exposed by annotations is not used internally by Kubernetes. Is not queryable, cannot be used in selectors. The  annotation keys and values are not constrained. Stored in [[Kubernetes_Manifest_Metadata#annotations|.metadata.annotations]].
<syntaxhighlight lang='yaml'>
apiVersion: apps/v1
kind: Deployment
spec:
  template:
    metadata:
      annotations:
        sidecar.istio.io/inject: "true"
...
</syntaxhighlight>
Setting an annotation on Deployment itself, in the Deployment's metadata, makes it propagate to the ReplicaSet.

Latest revision as of 23:27, 11 July 2023

External

Internal

Overview

Labels

A label is a key/value pair contains identifying information used to organize and categorize (scope and select) objects.

Labels are used by selector queries, or within selector sections of object definitions. Replicaset controllers and services use selectors to identify the pods that fall under their scope.

Labels is a mechanism to define loose couplings.

The structure of keys and values is constrained, so they can be evaluated quickly.

TODO:

For a specific object declaration, the labels are specified in the metadata section of the manifest.

Annotations

https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/

An annotation contains non-identifying information. The information exposed by annotations is not used internally by Kubernetes. Is not queryable, cannot be used in selectors. The annotation keys and values are not constrained. Stored in .metadata.annotations.

apiVersion: apps/v1
kind: Deployment
spec:
  template:
    metadata:
      annotations:
        sidecar.istio.io/inject: "true"
...

Setting an annotation on Deployment itself, in the Deployment's metadata, makes it propagate to the ReplicaSet.