Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save zulhfreelancer/8a3c5c5a2cc61e320f886183c0d35c98 to your computer and use it in GitHub Desktop.
Save zulhfreelancer/8a3c5c5a2cc61e320f886183c0d35c98 to your computer and use it in GitHub Desktop.
How to filter Kubernetes nodes by label using kubectl and jq

How to filter Kubernetes nodes by label using kubectl and jq

# Get all control-plane nodes
kubectl get nodes -o json | jq -r '.items[] | select(.metadata.labels."node-role.kubernetes.io/control-plane"=="true").metadata.name'

# Get all worker nodes
kubectl get nodes -o json | jq -r '.items[] | select(.metadata.labels."node-role.kubernetes.io/control-plane"!="true").metadata.name'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment