How to locate instances within an EKS cluster?

8/28/2019

How can I see which instances are associated with an EKS cluster?

I can use the AWS CLI to list cluster names and describe clusters, but how can I see which instances are actually in the cluster?

aws eks list-clusters --region us-east-1

    "clusters": [
        "foo-cluster",
        "bar-cluster"
    ]
}

aws eks describe-cluster --name foo-cluster

{
    "cluster": {
        "name": "foo-cluster",
        "arn": "arn:aws:eks:us-east-1:12345:cluster/foo-cluster",
        "createdAt": 1554068824.493,
        "version": "1.13",
        "endpoint": "https://12345.abc.us-east-1.eks.amazonaws.com",
        "roleArn": "arn:aws:iam::12345:role/foo-cluster12345",
        "resourcesVpcConfig": {
            "subnetIds": [
                "subnet-45678",
                "subnet-34567",
                "subnet-23456",
                "subnet-12345"
            ],
            "securityGroupIds": [
                "sg-12345"
            ],
            "vpcId": "vpc-12345"
        },
        "status": "ACTIVE",
        "certificateAuthority": {
            "data": "zubzubzub="
        },
        "platformVersion": "eks.2"
    }
}
-- jjones
aws-cli
cluster-computing
containers
kubernetes
nodes

1 Answer

8/28/2019

You can't from the aws eks ... CLI specifically. Kubernetes nodes are basically EC2 instances, so hopefully, you tagged your instances appropriately when you created them, typically with an Autoscaling Group with a tool like eksctl.

Your instances typically will have a 'Name' tag that is the same as the worker node name. So you could do:

$ aws ec2 describe-instances --filters Name=tag:Name,Values=node-name

Alternatively, you can get either the NAME or the INTERNAL-IP of the node with:

$ kubectl get nodes -o=wide

Then you can find your instances based on that:

$ aws ec2 describe-instances --filter Name=private-dns-name,Values=NAME
$ aws ec2 describe-instances --filter Name=private-ip-address,Values=INTERNAL-IP

Alternative, you can query the autoscaling group:

$ aws autoscaling describe-auto-scaling-groups --auto-scaling-group-names <your-asg-name> | jq .AutoScalingGroups[0].Instances[].InstanceId
-- Rico
Source: StackOverflow