How to Configure Karpenter to Wait Before Forcefully Terminating Pods?

June 6, 2025 4 answers
Asked by piano pedals
I'm using Karpenter with an EKS setup that relies on EC2 spot instances. I have an application that requires a 30-second grace period before the pods can be terminated. I've set a lifecycle hook (preStop) which works fine when I manually drain nodes or delete pods. However, I'm encountering an issue where Karpenter forcefully evicts pods when it gets a spot interruption message via SQS. Although my application doesn't crash due to a configured pod disruption budget (PDB), I need to find a way to get Karpenter to respect that 30-second wait time before terminating the pods. Any suggestions?

Answers

island-hopping-route
Have you looked into the terminationGracePeriod setting for your node pool? Apparently, Karpenter allows you to specify a grace period, and if you check out their documentation, it mentions how to set that up. It might help with your timing issue! Check out this link for more details: [Karpenter Node Pools](https://karpenter.sh/docs/concepts/nodepools/#spectemplatespecterminationgraceperiod).

_radish row: Thanks for the tip! I thought that if I didnโ€™t set it, it would just act like a normal drain without forceful terminations.

Reply to this answer
lOwerVolume
Just a thought โ€“ did you ensure that you set both the preStop hook and the terminationGracePeriodSeconds? Iโ€™ve seen some users overlook that, thinking the preStop was enough. It might be worth double-checking.

piano pedals: Yes, I set both to 100 seconds. The manual drains work fine, but when spot interruptions hit, it seems like the pods just get yanked out immediately.

Reply to this answer
v12~delta
Have you configured the AWS event rules for spot instance termination alerts when setting up Karpenter? Plus, setting up the interruption queue could be crucial; it might allow you to manage the evictions better.
Reply to this answer
radon detector check
Hey, since you're all about spot instances, you're probably saving a ton! If you haven't already checked it out, Rackspace Spot offers some neat features like pre-emption notifications and real-time capacity insights, which could help mitigate these issues. Just something to consider!
Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions