Require that pods have a certain label before they run on certain nodes

Say I have some special nodes in my cluster, and I want to be able to identify with a label all pods running on these nodes.

Taints & tolerations are close to this, but afaik tolerations aren’t labels, they’re their own thing, and can’t be referenced in places where you expect a label selector, right? Is there any way to require all pods running on these nodes to identify themselves in a way that can then be queried via label selectors?

Hi Alec,
I think we can use nodeSelector in this case.

1- label a worker node e.g. lets call it size=large.
kubectl label nodes worker01 size=large

2- create a pod definition with nodeSelector- say pod.yml
apiVersion: v1
kind: Pod
metadata:
labels:
size: large
name: test-pod
spec:
containers:

  • image: nginx
    name: test-pod
    nodeSelector:
    size: large
    3- create the pod
    kubectl create -f pod.yml

4- now you can search the pods running with the label size=large
vagrant@master01:~$ kubectl get pods --selector size=large
NAME READY STATUS RESTARTS AGE
test-pod 1/1 Running 0 28s
vagrant@master01:~$

Hope this helps.

Thank you
Amit Raj