Zero-Downtime Node Draining in EKS Spot Fleets
Wiring NTH, EventBridge, SQS, and ASG lifecycle hooks so a 120-second spot reclaim triggers graceful pod drain instead of abrupt eviction.

Advertising disclosure: this article includes partner links. KBY may earn a commission if you sign up or buy through one, at no extra cost to you. How we make money.
Underlined words are defined in the KBY Lexicon. Tap or click one to see what it means.
When EC2 reclaims a Spot Instance it gives two minutes’ notice. A pod’s default graceful termination period is 30 seconds. If nothing acts on that notice, the pods on the node are killed mid-request rather than moved: in-flight connections and gRPC streams are reset and clients retry against the replicas that are left. Good spot interruption handling moves those pods while the node is still running.
This article sets out one design for automating spot interruption handling on Amazon EKS: the AWS Node Termination Handler (NTH) in Queue Processor mode, fed by EventBridge rules through an SQS queue, with a termination lifecycle hook on each Auto Scaling group. It assumes self-managed node groups: Auto Scaling groups you create and own. The NTH README is explicit that “If you’re using EKS managed node groups, you don’t need the aws-node-termination-handler”: managed node groups enable Capacity Rebalancing and drain Spot nodes themselves. If Karpenter provisions your nodes, use its own interruption handling (the --interruption-queue setting); the Karpenter docs suggest adding NTH only to act on rebalance recommendations, and warn that it adds node churn.
#Why the kubelet alone is not enough
EC2 announces a Spot interruption two minutes ahead in two places: in instance metadata at /latest/meta-data/spot/instance-action, and as an EC2 Spot Instance Interruption Warning event in EventBridge. AWS says both are emitted on a best-effort basis. The kubelet watches neither. Left alone, the sequence is:
- EC2 stops or terminates the instance when the two minutes are up.
- The control plane marks the node unhealthy only after it has been unresponsive for
node-monitor-grace-period, which defaults to 50 seconds in kube-controller-manager. - Pods are evicted, and replacements scheduled, only once the automatic 300-second toleration for the
node.kubernetes.io/not-readyandnode.kubernetes.io/unreachabletaints (5 minutes) runs out, or the Node object is deleted.
The arithmetic does not work. A two-minute warning followed by a detection-and-eviction cycle measured in minutes means workloads are killed, not rescheduled. Draining without downtime needs something that acts on the signal while the node is still healthy: cordon it and evict its pods through the Kubernetes API before EC2 takes the instance.
#One handler, one queue
NTH runs in one of two modes. In IMDS mode it is a DaemonSet that watches instance metadata on every node. In Queue Processor mode it is a Deployment that reads events from an SQS queue fed by Amazon EventBridge. The README states that “Queue Processor Mode and IMDS Processor Mode cannot be run at the same time”, and setting enableSqsTerminationDraining to true switches IMDS monitoring off even if IMDS options are also set.

This design uses Queue Processor mode. It is the only mode that handles ASG termination lifecycle hooks (scale-in, Availability Zone rebalancing, unhealthy instance replacement), and the README’s comparison table shows it also covering Spot interruption notices, rebalance recommendations, scheduled maintenance through AWS Health, and instances terminated from the console or API.
When NTH reads one of these events it cordons the node, so nothing new is scheduled there, and then drains it. In Queue Processor mode every event is cordoned and drained unless cordonOnly is set. Draining uses the Eviction API, which respects PodDisruptionBudgets. For an ASG-initiated termination NTH then completes the lifecycle action, and only then does the group tell EC2 to terminate the instance. So ASG-initiated terminations wait for Kubernetes to move the workloads, up to the hook’s heartbeat timeout.
A lifecycle hook cannot hold back a Spot reclaim. The EC2 Auto Scaling documentation says a hook “does not prevent an instance from terminating in the event that capacity is no longer available”, so a drain that starts at the interruption notice must fit inside two minutes. Run the NTH pods themselves on On-Demand nodes, where the EKS documentation recommends running cluster management tools, so a reclaim never takes out the handler.
#Act on the rebalance recommendation, not the last warning
The two-minute interruption notice is the last signal you get. A rebalance recommendation tells you a Spot Instance is at elevated risk of interruption. It can arrive sooner than the notice, but AWS says it is not always possible to send it first, so it can also arrive together with the notice. The EC2 Auto Scaling documentation adds that before interrupting an instance, EC2 always gives both signals.
With Capacity Rebalancing enabled, the Auto Scaling group launches a replacement when a recommendation arrives, waits for it to pass its health checks, then terminates the at-risk instance through the termination lifecycle hook, which NTH drains like any scale-in; for an interruption notice it sends the hook while launching the replacement. The NTH README says that in this set-up you do not need the Spot and rebalance EventBridge rules. Without Capacity Rebalancing, keep those rules: NTH drains on the rebalance event itself, and the group replaces the instance only after the interruption. This design turns Capacity Rebalancing on, so spot interruption handling starts from the earliest signal.
#Rolling it out
The rollout goes in this order:
- Create the SQS queue, a queue policy that lets EventBridge send to it, and rules for
EC2 Instance-terminate Lifecycle Action,EC2 Instance State-change Notificationand AWS Health scheduled changes. Add rules forEC2 Spot Instance Interruption WarningandEC2 Instance Rebalance Recommendationonly if Capacity Rebalancing is off. - Turn on Capacity Rebalancing for each Spot group, with several instance types across several Availability Zones, as the EC2 Auto Scaling documentation recommends.
- Add a termination lifecycle hook on
autoscaling:EC2_INSTANCE_TERMINATING. The NTH README’s example uses a 300-second heartbeat timeout withCONTINUEas the default result. Make it longer than your slowest drain, or have NTH send heartbeats (below). - Tag each group with
aws-node-termination-handler/managedand propagate the tag at launch. By default NTH only acts on instances that carry it. - Install NTH once, in Queue Processor mode, with an IAM role for its service account (IRSA). Do not also install the IMDS-mode DaemonSet.
- Define PodDisruptionBudgets for every workload that must keep a minimum number of replicas through a drain.
- Set
terminationGracePeriodSecondsper workload to the time its connections need to close, remembering that a Spot drain has two minutes in total. - Test with a real interruption from AWS Fault Injection Service (behind the EC2 console’s Initiate interruption action): the instance gets a rebalance recommendation, then the two-minute notice, then it is interrupted. Check that its pods are running elsewhere before it goes.
#Code and Configurations
#1. SQS Queue, EventBridge Rules and Lifecycle Hook (Terraform)
1resource "aws_sqs_queue" "nth_interruption_queue" {
2 name = "eks-spot-interruption-queue"
3 message_retention_seconds = 300
4 sqs_managed_sse_enabled = true
5}
6
7# EventBridge needs permission to deliver to the queue
8resource "aws_sqs_queue_policy" "nth" {
9 queue_url = aws_sqs_queue.nth_interruption_queue.id
10 policy = jsonencode({
11 Version = "2012-10-17"
12 Statement = [{
13 Effect = "Allow"
14 Principal = { Service = ["events.amazonaws.com", "sqs.amazonaws.com"] }
15 Action = "sqs:SendMessage"
16 Resource = aws_sqs_queue.nth_interruption_queue.arn
17 }]
18 })
19}
20
21resource "aws_cloudwatch_event_rule" "asg_terminate" {
22 name = "capture-asg-terminate-lifecycle"
23 event_pattern = jsonencode({
24 source = ["aws.autoscaling"]
25 detail-type = ["EC2 Instance-terminate Lifecycle Action"]
26 })
27}
28
29resource "aws_cloudwatch_event_target" "asg_to_sqs" {
30 rule = aws_cloudwatch_event_rule.asg_terminate.name
31 target_id = "send-to-sqs"
32 arn = aws_sqs_queue.nth_interruption_queue.arn
33}
34
35resource "aws_cloudwatch_event_rule" "ec2_events" {
36 name = "capture-ec2-instance-events"
37 event_pattern = jsonencode({
38 source = ["aws.ec2"]
39 detail-type = [
40 "EC2 Instance State-change Notification"
41 # Add "EC2 Spot Instance Interruption Warning" and
42 # "EC2 Instance Rebalance Recommendation" if capacity_rebalance is off
43 ]
44 })
45}
46
47resource "aws_cloudwatch_event_target" "ec2_to_sqs" {
48 rule = aws_cloudwatch_event_rule.ec2_events.name
49 target_id = "send-to-sqs"
50 arn = aws_sqs_queue.nth_interruption_queue.arn
51}
52
53resource "aws_cloudwatch_event_rule" "scheduled_change" {
54 name = "capture-ec2-scheduled-change"
55 event_pattern = jsonencode({
56 source = ["aws.health"]
57 detail-type = ["AWS Health Event"]
58 detail = {
59 service = ["EC2"]
60 eventTypeCategory = ["scheduledChange"]
61 }
62 })
63}
64
65resource "aws_cloudwatch_event_target" "health_to_sqs" {
66 rule = aws_cloudwatch_event_rule.scheduled_change.name
67 target_id = "send-to-sqs"
68 arn = aws_sqs_queue.nth_interruption_queue.arn
69}
70
71# The self-managed Spot node group (other arguments omitted)
72resource "aws_autoscaling_group" "spot_pool" {
73 # ...
74 capacity_rebalance = true
75
76 tag {
77 key = "aws-node-termination-handler/managed"
78 value = ""
79 propagate_at_launch = true
80 }
81}
82
83resource "aws_autoscaling_lifecycle_hook" "terminating" {
84 name = "nth-terminating-hook"
85 autoscaling_group_name = aws_autoscaling_group.spot_pool.name
86 lifecycle_transition = "autoscaling:EC2_INSTANCE_TERMINATING"
87 heartbeat_timeout = 300
88 default_result = "CONTINUE"
89}#2. NTH in Queue Processor Mode (Helm values)
1# values.yaml for oci://public.ecr.aws/aws-ec2/helm/aws-node-termination-handler
2enableSqsTerminationDraining: true # Queue Processor mode: IMDS paths are not monitored
3queueURL: "https://sqs.eu-west-1.amazonaws.com/111111111111/eks-spot-interruption-queue"
4replicas: 2
5podDisruptionBudget:
6 maxUnavailable: 1
7serviceAccount:
8 create: true
9 name: aws-node-termination-handler
10 annotations:
11 eks.amazonaws.com/role-arn: arn:aws:iam::111111111111:role/nth-queue-processor
12nodeSelector:
13 node-lifecycle: on-demand # your own label for On-Demand nodes
14podTerminationGracePeriod: -1 # use each pod's terminationGracePeriodSeconds
15webhookURLSecretName: nth-webhook # Secret with the key webhookurlWith enableSqsTerminationDraining true the chart installs a Deployment and no DaemonSet.
#3. PodDisruptionBudget for Drain-Safe Rescheduling
1apiVersion: policy/v1
2kind: PodDisruptionBudget
3metadata:
4 name: checkout-service-pdb
5 namespace: payments
6spec:
7 minAvailable: 2
8 selector:
9 matchLabels:
10 app: checkout-serviceWithout a PodDisruptionBudget, nothing limits how many replicas of an application a drain evicts at once, so a reclaim that hits several nodes together can take a Deployment or StatefulSet down to zero. With one, the Eviction API refuses any eviction that would break the budget, answering 429 Too Many Requests, and the eviction can be tried again later. On Spot the protection has a limit: a budget can slow a drain, but it cannot stop EC2 taking the instance when the two minutes are up, so size replica counts and budgets so that a drain can finish inside the notice.

#What goes wrong
These failure modes are specific to spot interruption handling:
- Several nodes reclaimed together: the EKS documentation, describing how managed node groups drain Spot nodes, notes that evictions run one after another, so during multiple simultaneous reclamations some pods receive their eviction late. If your PDBs and topology spread constraints assume nodes fail one at a time, one event can breach
minAvailablefor several services. More instance types per group give it more Spot capacity pools to draw from. - Drains that outlast the notice: the same EKS page recommends termination grace periods of 30 seconds or less for Spot workloads, and warns that pods on dense nodes or with long grace periods may be killed without a termination signal. NTH also processes at most
workersevents in parallel (10 by default), so a burst of interruptions queues behind it. - Lifecycle hook timeout: for a terminating instance, the EC2 Auto Scaling documentation says both
CONTINUEandABANDONlet the instance terminate;ABANDONonly skips any remaining hooks. If NTH has not completed the lifecycle action when the heartbeat timeout runs out, the instance goes regardless of drain state. For long drains, setheartbeatInterval(30 to 3,600 seconds): NTH then renews the hook, up to 48 hours or 100 times the heartbeat timeout, whichever is smaller. - NTH ignoring a node: with the default
checkTagBeforeDraining: true, an instance without theaws-node-termination-handler/managedtag is not drained. NTH also finds the Kubernetes node by the event’s private DNS hostname; if your node names differ, setuseProviderId: trueso it matches on the node’s ProviderID. - Karpenter in the same cluster: Karpenter handles interruptions for its own nodes through its own queue. Keep NTH to the Auto Scaling group nodes; the managed tag does that.
- Stateful workloads with EBS volumes: a StatefulSet pod cannot start on its new node until the CSI driver has detached its volume from the old one and attached it to the new one. Measure how long that takes in your own tests. The chart’s
completeLifecycleActionDelaySecondspauses after the drain before NTH completes the lifecycle action, which the chart notes may help when pods use persistent volume claims.
#Permissions, replicas and alert noise
Some choices need sign-off from platform and security teams, not only the team applying architectural patterns for resilience:
- IAM scope for Queue Processor mode: NTH needs
autoscaling:CompleteLifecycleAction,autoscaling:DescribeAutoScalingInstances,autoscaling:DescribeTags,ec2:DescribeInstances,sqs:ReceiveMessageandsqs:DeleteMessage. The README’s example policy uses"Resource": "*". NarrowCompleteLifecycleActionto the node groups’ ASG ARNs and the SQS actions to the queue ARN, through IRSA. The Describe actions do not support resource-level permissions, so they stay on*. - No IMDS dependency: Queue Processor mode reads no instance metadata paths, and the README says it is safe to disable IMDS for the NTH pod. It takes its region from
awsRegion, theAWS_REGIONvariable or the queue URL. - Handler replicas: the chart runs one replica by default. More replicas help when events queue up or NTH’s own node is drained, but the chart warns they may send duplicate webhooks.
- Alert noise: a Slack or PagerDuty webhook for every interruption is an audit trail on a small fleet and noise on a large one. Pass the URL as a Secret (
webhookURLSecretName), useemitKubernetesEventsorenablePrometheusServerfor the routine record, and page only on failed drains and hook timeouts.
Treat spot interruption handling as a reliability control you design and test, not a chart you install once. One handler in Queue Processor mode reading one queue, lifecycle hooks on the groups it manages, Capacity Rebalancing to start replacements early, and PodDisruptionBudgets and grace periods that fit inside two minutes are what turn a Spot reclaim into a reschedule rather than an outage.
#Related reading
kubelet Anonymous Auth Left On Grants Unauthenticated Root-Level Node API Access
Node Pressure Eviction
Bin-Packing CI Jobs Across Runner Fleets
Aggregated ClusterRole Labels Silently Grant Unreviewed RBAC Permissions
Evidence trail
Sources and verification
Primary documentation and external technical references used in this article.
About this page
Credited to
Dates
Published
Last updated
Recommended reading
Guides from KBY that go with this article.



Education ITKeeping pupil data safe on your school laptop, and what to do the moment it goes missing
10 min read
Discover more
Was this useful?
Reports go to the site owner and are used to correct pages. Corrections are listed at /corrections.
Engineering insights, direct to you.
Receive the latest Systems Engineering tutorials, production guides, Engineering Labs and operational best practices.
Comments
Add a thoughtful note on Zero-Downtime Node Draining in EKS Spot Fleets. Comments are checked for spam and held for moderation before appearing.