By using AWS re:Post, you agree to the Terms of Use
/Query EKS node information with Python Boto3 or AWS CLI/

Query EKS node information with Python Boto3 or AWS CLI

0

I've been trying to pull the container runtime programmatically with the AWS CLI or Boto3, but haven't been able to find a specific class or method that provides the information I'm looking for. The information I'm looking for is documented here on line item number 4.: https://docs.aws.amazon.com/eks/latest/userguide/view-nodes.html

I've searched through the EKS client class in boto3 documentation and haven't found anything that would get more granular than using describe_cluster() and into the node details: https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/eks.html

As far as infrastructure goes, I followed the exact example from the AWS documentation for setting up EKS with fargate nodes: https://docs.aws.amazon.com/eks/latest/userguide/getting-started-console.html

I can see on the nodes page that it includes all the information I'm looking for, but I'm not sure what class would provide me that information programmatically.

The intent is to pull container runtimes across all EKS clusters from multiple AWS accounts.

Thanks!

1 Answers
1
Accepted Answer

With an EKS cluster, you can gather information in the EKS level or in the Kubernetes level. In the EKS level, you can use eksctl tool or the Boto EKS Client, but at this level, you can only look into cluster/nodegroup information. What you want is node information. So you have to query at Kubernetes level. You could use kubectl tool to create your query. For example:

# list all nodes in the cluster with their labels
kubectl get nodes --show-labels
# list all nodes in a specific nodegroup
kubectl get node --selector='eks.amazonaws.com/nodegroup=x86-br-spot-xl'

If you want to do this in Python, you could use Kubernetes Python Client.

from kubernetes import client, config

# Configs can be set in Configuration class directly or using helper utility
config.load_kube_config()

k8s_api = client.CoreV1Api()
logger.info("Getting k8s nodes...")
response = k8s_api.list_node()

You should look into Kubernetes documentation on how to get all the info you want with kubectl and then translate it later to Python.

answered a month ago
  • This makes sense. I was hoping I would be able to query it from the AWS console as it is in there to view.

    I'll deep dive into using kubectl and see what I can do.

    Thanks!

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions