thiagowfx's avatar

¬ just serendipity 🍀 (not just serendipity)

kubernetes: list pending pods in daemonset

• 119 words • 1 min • updated

⚠️ This post is over one year old. It may no longer be up to date or relevant. Opinions may have changed.

Problem statement: Given a DaemonSet with a couple of pods stuck in “Pending” state during their rollout, find out which nodes did not yet complete the pod initialization.

shell
% kubectl get nodes -o name | grep -vFf <(kubectl get pods -n {namespace} -l {ds-label-selector} -o wide --no-headers | awk '{print "node/" $7}')
node/aks-database-12345678-vmss000000
node/aks-database-12345678-vmss000002
node/aks-systempool-87654321-vmss000000
node/aks-systempool-87654321-vmss000001

Notes:

  • kubectl get nodes -o name: list all node names in the node/<name> form
  • kubectl get pods [...] -o wide: get the node name for each running DaemonSet pod
  • awk '{print "node/" $7}': get the node name matching the output of get nodes
  • grep [...]: find the nodes we are looking for

Surely there must be an easier way to accomplish this?