Skip to content

Commit dc6be0f

Browse files
committed
Revise formatting for updated README
1 parent 0f4f825 commit dc6be0f

File tree

2 files changed

+39
-46
lines changed

2 files changed

+39
-46
lines changed

README.md

Lines changed: 38 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,9 @@ You'll need the following AWS infrastructure components:
207207

208208
1. Amazon Simple Queue Service (SQS) Queue
209209
2. AutoScaling Group Termination Lifecycle Hook
210-
3. Amazon EventBridge Rule
211-
4. IAM Role for the aws-node-termination-handler Queue Processing Pods
210+
3. Instance Tagging
211+
4. Amazon EventBridge Rule
212+
5. IAM Role for the aws-node-termination-handler Queue Processing Pods
212213

213214
Optional AWS infrastructure components:
214215
1. AutoScaling Group Launch Lifecycle Hook
@@ -262,9 +263,7 @@ There are some caveats when using [server side encryption with SQS](https://docs
262263

263264
#### 2. Create an ASG Termination Lifecycle Hook:
264265

265-
##### 2.1. Send Notification via EventBridge
266-
267-
This will configure ASG to send termination notifications to EventBridge.
266+
Here is the AWS CLI command to create a termination lifecycle hook on an existing ASG when using EventBridge, although this should really be configured via your favorite infrastructure-as-code tool like CloudFormation or Terraform:
268267

269268
```
270269
aws autoscaling put-lifecycle-hook \
@@ -275,9 +274,7 @@ aws autoscaling put-lifecycle-hook \
275274
--heartbeat-timeout=300
276275
```
277276

278-
##### 2.2. Send notifications directly to SQS
279-
280-
This will configure ASG to send termination notifications directly to an SQS queue monitored by NTH.
277+
If you want to avoid using EventBridge and instead send ASG Lifecycle events directly to SQS, instead use the following command, using the ARNs from Step 1:
281278

282279
```
283280
aws autoscaling put-lifecycle-hook \
@@ -290,41 +287,7 @@ aws autoscaling put-lifecycle-hook \
290287
--role-arn <your SQS access role ARN here>
291288
```
292289

293-
#### 3. Handle ASG Instance Launch Lifecycle Notifications (optional):
294-
295-
If [Capacity Rebalance](https://docs.aws.amazon.com/autoscaling/ec2/userguide/ec2-auto-scaling-capacity-rebalancing.html) is configured for your ASG, a new instance will be launched before another's termination. The use of an ASG launch lifecycle hook, as configured below, can verify the new instance has successfully connected as a Kubernetes node.
296-
297-
##### 3.1. Send Notification via EventBridge
298-
299-
This will configure ASG to send launch notifications to EventBridge.
300-
301-
```
302-
aws autoscaling put-lifecycle-hook \
303-
--lifecycle-hook-name=my-k8s-launch-hook \
304-
--auto-scaling-group-name=my-k8s-asg \
305-
--lifecycle-transition=autoscaling:EC2_INSTANCE_LAUNCHING \
306-
--default-result="ABANDON" \
307-
--heartbeat-timeout=300
308-
```
309-
310-
##### 3.2. Send notifications directly to SQS
311-
312-
This will configure ASG to send launch notifications directly to an SQS queue monitored by NTH.
313-
314-
```
315-
aws autoscaling put-lifecycle-hook \
316-
--lifecycle-hook-name=my-k8s-launch-hook \
317-
--auto-scaling-group-name=my-k8s-asg \
318-
--lifecycle-transition=autoscaling:EC2_INSTANCE_LAUNCHING \
319-
--default-result="ABANDON" \
320-
--heartbeat-timeout=300 \
321-
--notification-target-arn <your queue ARN here> \
322-
--role-arn <your SQS access role ARN here>
323-
```
324-
325-
When NTH receives a launch notification, it will periodically check for a node backed by the EC2 instance to join the cluster and for the node to have a status of 'ready.' Once a node becomes ready, NTH will complete the lifecycle hook, prompting the ASG to proceed with terminating the previous instance. If the lifecycle hook is not completed before the timeout, the ASG will take the default action. If the default action is 'ABANDON,' the new instance will be terminated, and the notification process will be repeated with another new instance.
326-
327-
#### 4. Tag the Instances:
290+
#### 3. Tag the Instances:
328291

329292
By default the aws-node-termination-handler will only manage terminations for instances tagged with `key=aws-node-termination-handler/managed`.
330293
The value of the key does not matter.
@@ -350,7 +313,7 @@ You can also control what resources NTH manages by adding the resource ARNs to y
350313

351314
Take a look at the docs on how to [create rules that only manage certain ASGs](https://docs.aws.amazon.com/autoscaling/ec2/userguide/cloud-watch-events.html), and read about all the [supported ASG events](https://docs.aws.amazon.com/autoscaling/ec2/userguide/ec2-auto-scaling-event-reference.html).
352315

353-
#### 5. Create Amazon EventBridge Rules
316+
#### 4. Create Amazon EventBridge Rules
354317

355318
You may skip this step if sending events from ASG to SQS directly.
356319

@@ -397,7 +360,7 @@ aws events put-targets --rule MyK8sScheduledChangeRule \
397360
--targets "Id"="1","Arn"="arn:aws:sqs:us-east-1:123456789012:MyK8sTermQueue"
398361
```
399362

400-
#### 6. Create an IAM Role for the Pods
363+
#### 5. Create an IAM Role for the Pods
401364

402365
There are many different ways to allow the aws-node-termination-handler pods to assume a role:
403366

@@ -428,6 +391,36 @@ IAM Policy for aws-node-termination-handler Deployment:
428391
}
429392
```
430393

394+
#### 1. Handle ASG Instance Launch Lifecycle Notifications (optional):
395+
396+
NTH can monitor for new instances launched by an ASG and notify the ASG when the instance is available in the EKS cluster.
397+
398+
NTH will need to receive notifications of new instance launches within the ASG. We can add a lifecycle hook to the ASG that will send instance launch notifications via EventBridge:
399+
400+
```
401+
aws autoscaling put-lifecycle-hook \
402+
--lifecycle-hook-name=my-k8s-launch-hook \
403+
--auto-scaling-group-name=my-k8s-asg \
404+
--lifecycle-transition=autoscaling:EC2_INSTANCE_LAUNCHING \
405+
--default-result="ABANDON" \
406+
--heartbeat-timeout=300
407+
```
408+
409+
Alternatively, ASG can send the instance launch notification directly to an SQS Queue:
410+
411+
```
412+
aws autoscaling put-lifecycle-hook \
413+
--lifecycle-hook-name=my-k8s-launch-hook \
414+
--auto-scaling-group-name=my-k8s-asg \
415+
--lifecycle-transition=autoscaling:EC2_INSTANCE_LAUNCHING \
416+
--default-result="ABANDON" \
417+
--heartbeat-timeout=300 \
418+
--notification-target-arn <your queue ARN here> \
419+
--role-arn <your SQS access role ARN here>
420+
```
421+
422+
When NTH receives a launch notification, it will periodically check for a node backed by the EC2 instance to join the cluster and for the node to have a status of 'ready.' Once a node becomes ready, NTH will complete the lifecycle hook, prompting the ASG to proceed with terminating the previous instance. If the lifecycle hook is not completed before the timeout, the ASG will take the default action. If the default action is 'ABANDON', the new instance will be terminated, and the notification process will be repeated with another new instance.
423+
431424
### Installation
432425

433426
#### Pod Security Admission

test/e2e/asg-launch-lifecycle-sqs-test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ function test_launch_lifecycle {
415415
elapsed_time=$((current_time - start_time))
416416
if [[ $elapsed_time -ge $heartbeat_timeout ]]; then
417417
echo ""
418-
echo "Launch Lifecycle not Completed. Timeout Reached ❌"
418+
echo "❌ Timeout Reached ❌"
419419
exit 1
420420
fi
421421

0 commit comments

Comments
 (0)