aws / containers-roadmap

This is the public roadmap for AWS container services (ECS, ECR, Fargate, and EKS).
https://aws.amazon.com/about-aws/whats-new/containers/
Other
5.22k stars 321 forks source link

[EKS] [request]: Label nodes with instance-id #1395

Open arianvp opened 3 years ago

arianvp commented 3 years ago

Community Note

Tell us about your request I want nodes to have a label eks.amazonaws.com/instance-id=<id> added

Which service(s) is this request for? EKS

Tell us about the problem you're trying to solve. What are you trying to do, and why is it hard? When I have scheduled event alerts in AWS, I get the instance-id of the affected node. I then want to run kubectl get node -leks.amazonws.com/instance-id=$instanceId to quickly find out what kubernetes node is affected and e.g. drain it.

Are you currently working around this issue? I have the following script:

#!/usr/bin/env bash
set -euo pipefail

instanceId=$1
aws ec2 describe-instances --instance-ids "$instanceId" --query "Reservations[*].Instances[*][PrivateDnsName]" --output text

Which I call like this:

kubectl get node $(./hack/get-node-name.sh i-09687bfe3931549c6)

Additional context Anything else we should know?

Attachments If you think you might have additional information that you'd like to include via an attachment, please do - we'll take a look. (Remember to remove any personally-identifiable information.)

surajnarwade commented 2 years ago

Hi, I would like to see instance-id as a label as well.

meanwhile, you can find instance-id in spec.providerID of the node resource

spec.providerId looks like this aws:///eu-west-1a/i-01adxxxxxxxxxd

you may have to do some string magics to retrieve the instance id

kr3cj commented 12 months ago

I forget where I got this from, but for EKS managed node groups, we accomplished getting this label using preBootstrapCommands:

managedNodeGroups:
  ...
  preBootstrapCommands:
        - sed -i '/^KUBELET_EXTRA_ARGS=/a KUBELET_EXTRA_ARGS+=" --node-labels=instance=\$(curl\ http://169.254.169.254/latest/meta-data/instance-id)"' /etc/eks/bootstrap.sh

2/19/24 Update: Anyone know of an equivalent way to do this in Karpenter's NodeClass:

apiVersion: karpenter.k8s.aws/v1beta1
kind: EC2NodeClass
...
spec:
  userData: |
    #!/bin/bash
    sed -i '/^KUBELET_EXTRA_ARGS=/a KUBELET_EXTRA_ARGS+=" --node-labels=instance-id=\$(curl\ http://169.254.169.254/latest/meta-data/instance-id)"' /etc/eks/bootstrap.sh