Kubernetes API - gets list of Nodes hosting specific deployment/pods

4/5/2021

Say I have a 5 node cluster of kafka and a kubernetes cluster of 100 nodes.

Now, I want to find all 5 nodes (of 100) which is hosting kafka pod. So something like:

kubectl get nodes --selector="deployment.kafka"
-- codersofthedark
kubectl
kubernetes

1 Answer

4/5/2021

I dont think thats possible, what you can do is select your pods based on labels and get the node name, As @Krishna said in his comment, so the command will be

kubectl get pods -n NAMESPACE_NAME -l app=kafka  -o wide | awk '{print $7}'

app=kafka is the label on the pods, it might be different in your case

-- Ali Kahoot
Source: StackOverflow