Open In App

kubernetes Labels VS Annotations

Last Updated : 06 Feb, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

Kubernetes Labels are used to identify and choose resources according to certain criteria. Annotations are used to offer additional information about a resource rather than just identify or choose it. Required for selectors for developing services, deployments, and other resources that target certain resources. Kubernetes Labels are used to identify and choose resources according to certain criteria. Annotations are used to offer additional information about a resource rather than just identify or choose it.

Kubernetes Labels

Kubernetes Labels are key-value pairs that are applied to objects like Kubernetes Pods. Labels are designed to be used to indicate distinguishing qualities of objects that are meaningful and important to users, but they have no direct semantic implications for the main system. Thus, labels should be used when you want Kubernetes to organize a collection of relevant resources.

Example For Kubernetes Labels

  • For example, as you can see, every pod with the label “app: frontend” is chosen by the previous configuration state.
  • In this example, the Service will route traffic to all pods in the Kubernetes cluster labeled with “app: frontend” on targetPort: 8080.
   apiVersion: v1
kind: Service
metadata:
name: frontend-service
spec:
selector:
app: frontend
ports:
- protocol: TCP
port: 80
targetPort: 8080

Usage Of Kubernetes Labels

  • Labels can be used to provide network regulations that improve the security of the Kubernetes system.
  • Labels are also used to partition resources that are at high risk of being attacked owing to their sensitivity, as well as to ensure that only a specified set of users or service traffic has access to important resources.
  • Labels can also be used to segregate network traffic. One approach is to give labels to distinct endpoints from which traffic enters the system.
  • This may be accomplished by assigning labels to different types of people using the system and limiting the functions they can conduct.

Kubernetes Annotations

Kubernetes annotations are pieces of metadata that you may add to your Kubernetes objects, such as ReplicaSets and pods. Specifically, annotations are key-value mappings. Annotations allow you to divide your application into groups of properties that correspond to how you think about it.

Thus, if you wish to provide information about a resource to other humans, annotations are a preferable option.

Example For Kubernetes Annotations

For instance, you can see that the prior configuration state is kept in an annotation as structured data when you modify a Kubernetes deployment configuration:

 apiVersion: v1
kind: Pod
metadata:
name: my-pod
annotations:
buildVersion: v1.2.4
releaseNotes: "This pod is part of production environment."
configuration: |
{
"debug": false,
"maxRequests": 100
}
spec:
containers:
- name: my-container
image: my-image:v1.2.4

In this example, Annotations include buildVersion, releaseNotes, and configuration. The string value for buildVersion is “v1.2.4”. The build version, release notes, and configuration parameters of the pod are among the additional details provided by these annotations.

Usage Of Kubernetes Annotations

  • Phone or pager numbers of those in charge, or directory entries indicating where such information may be located, such as a team website.
  • Enable the Deployment object to keep track of the ReplicaSets it manages for rollouts.
  • Keep track of the “reason” for the most recent update to an object.
  • Communicate a specialised scheduling policy to a specialised scheduler.

Difference Between Kubernetes Labels Vs Annotations

Kubernetes Labels

Kubernetes Annotations

Kubernetes Labels are key-value pairs that are applied to objects like Pods.

Kubernetes annotations are pieces of metadata that you may add to your Kubernetes objects, such as ReplicaSets and pods

Kubernetes Labels are used to identify and choose resources according to certain criteria.

Kubernetes Annotations are used to offer additional information about a resource rather than just identify or choose it.

The name (up to 63 characters long) and prefix (up to 253 characters long) are necessary.

Name must be 63 characters or fewer. Prefix is optional.

Kubernetes Labels enable us to organise our things and execute searches for viewing and functioning.

Kubernetes Annotations are used to include non-identifying metadata with Kubernetes objects.

Conclusion

In Conclusion, Kubernetes Labels are key-value pairs that are applied to objects like Pods and annotations are pieces of metadata that you may add to your Kubernetes objects, such as ReplicaSets and pods. Annotations are used to offer additional information about a resource rather than just identify or choose it.

Kubernetes Labels And Annotations – FAQs

What Is The Use Of Annotations In Kubernetes?

Phone or pager numbers of those in charge, or directory entries indicating where such information may be located, such as a team website.

Why Do We Need Labels In Kubernetes?

Labels are key-value pairs that are applied to objects like Pods. Labels are designed to indicate distinguishing characteristics of items that are meaningful and relevant to consumers.

What Is The Main Purpose Of An Annotation?

Annotating is any activity that intentionally interacts with a text to increase the reader’s knowledge, recollection, and reaction to the material.

How Do I Remove Labels From Kubernetes?

Use the host-label-remove command to remove labels from Kubernetes

What Is The Function Of Labels In DevOps?

DevOps engineers may do bulk operations, identify items, arrange them according to certain criteria, diagnose issues, and more with the help of these labels.



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads