Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get pods on nodes with certain label

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)

like image 833
vrtx54234 Avatar asked Aug 25 '20 21:08

vrtx54234


People also ask

How do I run pods on a specific node?

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.

How do I get node pods?

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.


1 Answers

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.

like image 127
Mr.KoopaKiller Avatar answered Nov 15 '22 10:11

Mr.KoopaKiller