Ashutosh Kumar
Jul 14, 2018 · 2 min read

The resources that we create in a kubernetes cluster can be organised by using labels. Before we talk about field selector in Kubernetes, let us walk through quickly about labels.

Labels are key value pairs that can be used to identify, or group the resources in Kubernetes. In other words, labels can be used to select resources from a list.
You can label Kubernetes native resources as well as Custom Resources. To understand it more clearly, let us do some hands on practice on labels.

The tutorial will assume that you have a working minikube setup or a Kubernetes cluster setup.

Following is link to the yaml . It’s application will create a pod.

The yaml looks following:

apiVersion: v1
kind: Pod
name: example-pod
env: development
- name: label-example
image: sonasingh46/node-web-app:latest
- containerPort: 8000

Notice the bold text in above yaml. That is one way to add labels to a resource by specifying in yaml.
Let us create a pod by executing following command:

kubectl apply -f

You can use above command directly or copy the content to save it on your local machine in a file , say sample-pod.yaml.

ashutosh@miracle:~/Desktop/artifacts/samples$ kubectl apply -f sample-pod.yaml 
pod/example-pod created
ashutosh@miracle:~/Desktop/artifacts/samples$ kubectl get po
example-pod 1/1 Running 0 3m

Now, let us run the following commands to check for labels in the pod.

ashutosh@miracle:~/Desktop/artifacts/samples$ kubectl get pod example-pod --show-labelsNAME                      READY     STATUS    RESTARTS   AGE     LABELSexample-pod               1/1       Running   0          3m        env=development

As you can see in the above output example-pod is having a label of key value pair as env=development .
You can also do a kubectl get pod example-pod -o yaml to see all the fields along with labels.

Let us add another label to the above pod…

Read the complete article in MayaData’s Blog


MayaData delivers data agility through OpenEBS, Litmus, and MayaOnline.

Ashutosh Kumar

Written by



MayaData delivers data agility through OpenEBS, Litmus, and MayaOnline.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade