I am looking for a way to list all nodes in a specific nodepool but not able to find any examples.
Is there a way to specify meta data with json? Or use an awk filter?
The following will list all nodes in the cluster
kubectl get nodes
CodePudding user response:
Nodes have label with their node group. To print a list of all of yours nodes and their node group run:
> kubectl get node -o=custom-columns='node_name:metadata.name, node_group:metadata.labels.cloud\.google\.com/gke-nodepool'
node_name node_group
gke-ml-prd-default-node-pool-03d09fca-jj3x default-node-pool
gke-ml-prd-default-node-pool-4649f5b7-j1qc default-node-pool
gke-ml-prd-default-node-pool-4a9ff740-2my4 default-node-pool
gke-ml-prd-default-node-pool-9a199b2d-q573 default-node-pool
Of course you need to change the label according to your cloud provider.
Take a look on the labels of one of your nodes with kubectl describe <node_name>
and find the relevant label name.
These are names in the popular cloud providers.
- gke: cloud.google.com/gke-nodepool
- eks: eks.amazonaws.com/nodegroup
- aks: kubernetes.azure.com/agentpool
You can also filter for specific group with
kubectl get node --selector='cloud.google.com/gke-nodepool=default-node-pood'