Fetch Kubernetes node details for quick analysis of your worker nodes

What we are discussing on this blog?

Hey, this is not a big thing, however, sometimes it will help a lot on troubleshooting or understand the worker configurations without logging into the AWS console. You can use the kubectl CLI to get those informations to understand the worker node details in detail.

Why I wrote this? I was searching command to list all worker nodes with its AMI ID, but it took some time to get the exact command to satisfy my requirement. I know, it will get if I describe the node. But, think if we have hundreds of nodes in our cluster. We might need some effort to do those kind of analysis. We get all these informations from the UI or from the eksctl/awscli, but kubectl can do a lot of things for you.

Here, my requirement was for listing all nodes with its AMI ID, but it can give you a lot more information. Like; this can help you on: List Kubernets worker nodes which uses a particular instance type, list worker nodes running with SPOT / On DEMAND instances, list worker nodes running on a specific region / zone, list worker nodes with a specific launch template or specific launch template version, or based on any labels that you provided while creating the instance.

This is a small article, but it can save some time for you.

At first, I was doing kubectl describe on for loop to get the data for my requirement. Later got some other way to find / fetch the details in a simple way.

My requirement: Fetch nodes with its AMI details.

Way 1: Initially I was doing the describe on a for loop and fetching the details. For example; I made a list of nodes in a file and passed that to find the AMI details.

Save nodes to a text file

kubectl get nodes | grep -v NAME| awk {'print $1'} > nodes.txt

Then get the AMI details by doing kubectl describe in a loop

for i in $(cat nodes.txt); do echo "Node: $i and its AMI is: $(kubectl describe nodes $i | grep "eks.amazonaws.com/nodegroup-image"| cut -d "=" -f 2) "; done

This will meet you requirement. However, we have some better way to do this.

Way 2: By using kubectl directly

kubectl get nodes -o custom-columns=NAME:.metadata.name,AMI:'{.metadata.labels.eks\.amazonaws\.com/nodegroup-image}'

We can use these labels to understand the worker nodes details from CLI. EKS by default add few labels and also it includes the labels that we pass when we create the Node Groups. So we can use these labels for analysing the worker nodes from the CLI. Adding few other examples below:

Example 1: List out worker nodes which uses SPOT / ON DEMAND instances by using kubectl

kubectl get nodes -o custom-columns=NAME:.metadata.name,TYPE:'{.metadata.labels.eks\.amazonaws\.com/capacityType}'

Example 2: List out worker nodes with EC2 instance type by using kubectl

kubectl get nodes -o custom-columns=NAME:.metadata.name,TYPE:'{.metadata.labels.node\.kubernetes\.io/instance-type}'

Example 3: List out worker nodes running based on Availability Zone by using kubectl

kubectl get nodes -o custom-columns=NAME:.metadata.name,TYPE:'{.metadata.labels.failure-domain\.beta\.kubernetes\.io/zone}'

Yeah, not adding more. You can describe one worker node and check the available label and print based on your specific requirement. You can pipe and do further analysis grep/awk/sort for your requirement.

This will help you to create quick inventory of your EKS worker with these information.

Thanks for reading this. Share your suggestions and feedback.

Other related topics

, , ,

Post navigation

Arunlal Ashok

DevOps Engineer. Linux lover. Traveller.
Always happy for an open discussion! Write to arun ((@)) crybit ((dot)) com.

Leave a Reply

Your email address will not be published. Required fields are marked *