List Kubernetes nodes within a specific nodepool (Misc)

Running kubectl get nodes gives you a list of nodes within a cluster. If your cluster is running on something like GKE or AKS, you'll even be able to tell which nodepool each node is in because it's baked into the node name - allowing easy filtering with grep.

Unfortunately, on EKS, this isn't the case and node names are quite opaque.

However, most managed k8s providers push nodepool names into a label, so it's possible to tell kubectl to only list pods in a specific pool.

Note: if you use different instance types in each pool, you can also filter by instance-type

Details

  • Language: Misc

Snippet

# Assuming the nodepool in question is called mypool

# GKE
kubectl get nodes --selector='cloud.google.com/gke-nodepool=mypool'

# AKS
kubectl get nodes --selector='kubernetes.azure.com/agentpool=mypool'

# EKS
kubectl get nodes --selector='eks.amazonaws.com/nodegroup=mypool'

# DigitalOcean
kubectl get nodes --selector='doks.digitalocean.com/node-pool=mypool'

# Filter by instance type
kubectl get nodes --selector='node.kubernetes.io/instance-type=[type]'