K8s: Get all pods running on a node - Fri, Jun 10, 2022
K8s: Get all pods running on a node
Recently a node in our k8s cluster had networking problems and couldn’t pull images from our container registry. After finding out which node was not working correctly, I needed a way to get the name of the pods currently scheduled on that node and are in the state Pending
. After looking at the kubectl jsonpath support
it turned that it only has limited jsonpath
support. Specifically operators like &&
and ||
are not supported.
So I instead used jq
which supports operators:
kubectl get pods -n my-ns -o json | jq -r '.items[] | select(.spec.nodeName=="cluster-node-1" and .status.phase=="Pending") | .metadata.name'
The get pods
command returns an array of pod specifications
and their status
. The following statement selects all the pods all pods on that node and have the state Pending
. The output is a list of pod names.