How To Add Annotations Using Cli Commands
We discussed above about how to add annotations in a configuration file, now we will be discussing how to add annotations in the CLI itself. note that we will continue the same example.yaml service file from above and add annotations to the example service created above. In order to add annotations with the CLI commands, follow the given steps:
Step 1. Enter the following command in your terminal to find current annotations:
kubectl describe service example | grep -i "anno"
This will give a list of the current annotations. The output will be:
This is the annotation we created in the step by step guide above.
Step 2. “kubectl annotate” is used to add annotations in the service directly using CLI. Enter the following command in the terminal:
kubectl annotate service example a8r.io/description="this is an example service"
The annotation has been added to the example service. This will give you a similar output:
Step 3. You can view the current annotations by the command we used before:
kubectl describe service example | grep -i "anno"
Since we have added a new annotation, we will get the new annotation in the output:
We can also find annotations by the “kubectl describe service” command. you can do that by adding the following command in the terminal:
kubectl describe service example
How to Use Kubernetes Annotations?
Annotations are key-value pairs that are used to attach non-identifying metadata to Kubernetes objects. Various tools that are built over Kubernetes use this metadata attached by annotations to perform actions or enhance resource management. Labels and Annotations are used to attach metadata to Kubernetes objects. This makes annotations important for working with Kubernetes clusters. To learn more about Kubernetes cluster and its architecture refer to Kubernetes – Architecture.