containers-roadmap icon indicating copy to clipboard operation
containers-roadmap copied to clipboard

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

Open arianvp opened this issue 3 years ago • 1 comments

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

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.)

arianvp avatar Jun 04 '21 10:06 arianvp

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

surajnarwade avatar Jul 28 '22 16:07 surajnarwade

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

kr3cj avatar Nov 16 '23 16:11 kr3cj