Labels, Selectors, and Annotations
Labels are key/value pairs that are attached to objects, such as pods. Labels are intended to be used to specify identifying attributes of objects that are meaningful and relevant to users, but do not directly imply semantics to the core system. Labels can be used to organize and to select subsets of objects. Labels can be attached to objects at creation time and subsequently added and modified at any time. Each object can have a set of key/value labels defined. Each Key must be unique for a given object.
You can use Kubernetes annotations to attach arbitrary non-identifying metadata to objects. Clients such as tools and libraries can retrieve this metadata.
You can use either labels or annotations to attach metadata to Kubernetes objects. Labels can be used to select objects and to find collections of objects that satisfy certain conditions. In contrast, annotations are not used to identify and select objects. The metadata in an annotation can be small or large, structured or unstructured, and can include characters not permitted by labels.
Resources
-
CLI Label Commands
Read about the descriptions and example commands for OpenShift CLI (
oc
) developer commands.
-
Labels
Labels can be used to organize and to select subsets of objects.
-
Annotations
You can use Kubernetes annotations to attach arbitrary non-identifying metadata to objects.
References
apiVersion: v1
kind: Pod
metadata:
name: my-pod
labels:
app: foo
tier: frontend
env: dev
annotations:
imageregistry: "https://hub.docker.com/"
gitrepo: "https://github.com/csantanapr/knative"
spec:
containers:
- name: app
image: bitnami/nginx
Change Labels on Objects
Getting Pods based on their labels. Delete the Pod.Change Labels on Objects
Getting Pods based on their labels. Delete the Pod.