List pods running on a kubernetes node (Misc)

Running kubectl get pods is pretty straightfoward, but it can do also do a lot of filtering

If contention is suspected, it's often useful to be able to see what other workloads the underlying node is carrying

This snippet details getting node information from kubectl, with an example showing out how to list all pods that are running on the same node as a pod with a specific label.

Details

  • Language: Misc

Snippet

# List all pods with their nodes
kubectl get pods -o wide

# Filter by node id
kubectl get pods --field-selector spec.nodeName=MyNode

# Identify nodes and pods for specific app
kubectl get pods -l app=MyApp -o wide

Usage Example

# List all pods on all nodes running a pod for app MyApp
for node in `kubectl get pods -l app=MyApp -o wide --no-headers | awk '{print $7}'` do
    echo "$node"
    kubectl get pods --field-selector spec.nodeName="$node"
    echo ""
done