Labels

As soon as the number of applications grows within an organization, managing all of them tends to be a nightmare. Imagine that you only have fifteen microservices and two environments: one for staging and the other for production. In this case, identifying all of the running pods would be really hard to do, and you would need to remember all of the pod names in order to query their statuses.

Labels are intended to make this task easier. You can use them to tag pods with label names that are easy to remember and which make sense to you. Since a label is a key–value pair, you have the chance to use whatever you want, including environment:<environment-name>, for instance. Let's review the following application-xyz-pod.yaml example file:

apiVersion: v1
kind: Pod
metadata:
name: application-xyz
labels:
environment:production
otherLabelName: otherLabelValue
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80

- name: database
image: mysql
volumeMounts:
- name: mysql-data
mountPath: /path

- name: api
image: <your-api-image>

The code in bold shows how the label can be created. Here, you can add as many labels as you want. Let's create this pod with the following command:

kubectl create -f application-xyz-pod.yaml 

Once the pod has been created, you can look for it using the labels with the following command:

kubectl get pod -l environment=production
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.58.44.229