Skip to content

Instantly share code, notes, and snippets.

@snay2
Last active August 23, 2022 21:40
Show Gist options
  • Save snay2/b5499dc141887aabdc9a147ecf88c4d4 to your computer and use it in GitHub Desktop.
Save snay2/b5499dc141887aabdc9a147ecf88c4d4 to your computer and use it in GitHub Desktop.
How to spin up an EKS cluster and install NTH

These instructions were originally for my testing of aws/aws-node-termination-handler#669, but I'm putting them here for general reference in the future.

Creating an EKS cluster and installing NTH into it

  1. Create an EKS cluster with a managed node group using eksctl
eksctl create cluster --name nthCluster --region us-east-2
  1. Create an SQS queue and EventBridge rules using the CloudFormation template in this repo
  2. Modify the nodegroup IAM role (name similar to eksctl-*-nodegroup-ng-1-NodeInstanceRole-*) to add the following inline policy (or use the AmazonSQSFullAccess managed policy):
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "sqs:DeleteMessage",
                "sqs:ReceiveMessage"
            ],
            "Resource": "*"
        }
    ]
}
  1. Install NTH v1.17.0 into the cluster in Queue Processor mode
curl -L https://github.com/aws/aws-node-termination-handler/releases/download/v1.17.0/all-resources-queue-processor.yaml -o nth.yaml
# Open the YAML file and update QUEUE_URL value
kubectl apply -f ./nth.yaml
  1. (optional) Install Metrics Server into the cluster
kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml
kubectl top pod <pod_name>

Testing that NTH can receive messages via SQS

  1. Launch an EC2 instance:
simple-ec2 launch --capacity-type spot --tags aws-node-termination-handler/managed=
  1. Send that instance a Spot ITN:
ec2-spot-interrupter --interactive
  1. Verify that NTH receives the message from the queue

Testing with an NTH build from local changes

  1. Build NTH locally with these changes
make build-docker-images
  1. Push that container to an ECR repo you own
docker tag amazon/aws-node-termination-handler:<TAG_OF_LATEST_BUILD> <ECR_REPO_URL>:<TAG_OF_LATEST_BUILD>
docker push <ECR_REPO_URL>:<TAG_OF_LATEST_BUILD>
  1. Install that version of NTH into the EKS cluster
cp nth.yaml nth-my-build.yaml
# Edit nth-my-build.yaml to point to the ECR image we just pushed
kubectl apply -f ./nth-my-build.yaml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment