k8slearn-Labels Selectors and Annotations-03

Labels, Selectors, and Annotations in Kubernetes

Labels and Selectors are essential in Kubernetes for organizing and selecting resources. By labeling each Kubernetes resource, you can later use selectors to filter and apply actions to those resources.

Working with Labels and Selectors

To retrieve pods with a specific label, you can use the following command:

To retrieve pods with multiple label filters, use:

Example: Labels in a Pod

Here’s an example of how labels and annotations are defined within a Pod:

Example: Labels in a Deployment

In a Deployment, labels in the template section are used to label the Pods created by the deployment. These labels are then used by the deployment’s selector to group these Pods under the same deployment. If any existing Pod matches the label selector criteria, it will be managed by this deployment as well.

It’s important to note that the labels for the Deployment itself do not directly influence the labeling or selection of Pods.

Annotations in Kubernetes

Annotations provide additional, non-identifying information to Kubernetes objects. These annotations are not used by Kubernetes internally but can be leveraged by other tools and services running within the Kubernetes cluster.

Example of annotations in an Ingress resource:

Leave a Reply

Your email address will not be published. Required fields are marked *