This is an extension to the question here - how can I get the list pods running on nodes with a certain label?
I am trying to find the pods in a specific zone (failure-domain.beta.kubernetes.io/zone)
You can add the nodeSelector field to your Pod specification and specify the node labels you want the target node to have. Kubernetes only schedules the Pod onto nodes that have each of the labels you specify. See Assign Pods to Nodes for more information.
A Pod is a group of one or more containers with shared storage, network and lifecycle and is the basic deployable unit in Kubernetes. Each Pod is scheduled on the same Node, and remains there until termination or deletion. In this note i will show how to get Pods running on a specific Node using the kubectl command.
You can get all nodes' name with the label you want using for
command and list the pods within theses nodes:
Example:
for node in $(kubectl get nodes -l failure-domain.beta.kubernetes.io/zone=us-central1-c -ojsonpath='{.items[*].metadata.name}'); do kubectl get pods -A -owide --field-selector spec.nodeName=$node; done
The command will list all pods with label failure-domain.beta.kubernetes.io/zone=us-central1-c
and then list the pods.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With