[BUG] Evict-on-freeze ignores terminationGracePeriodSeconds: pods get about 1 second and preStop never completes
Describe the bug
With evict-on-freeze enabled, pods labelled remediator.kubernetes.azure.com/onFreeze are evicted with a grace period of about 1 second, regardless of the pod's terminationGracePeriodSeconds. As a result, a preStop hook never completes, and the application gets no time to shut down gracefully.
This happens even though the drain starts about 5 minutes before the freeze, which would leave enough time for a normal graceful termination. The PodDisruptionBudget is respected: the drain logs Cannot evict pod as it would violate the pod's disruption budget and retries later.
Related: #3463
To Reproduce
-
Apply the
remediator-configConfigMap inkube-systemwith"OnFreeze": { "Enabled": true }, as in the documentation. -
Deploy a workload with the
remediator.kubernetes.azure.com/onFreeze: ""pod label, a PodDisruptionBudget,terminationGracePeriodSeconds: 60, and thispreStophook:lifecycle: preStop: exec: command: ["sh", "-c", "sleep 40"] -
Wait for a freeze event on a node running one of the pods.
-
Look at the pod's events and the kubelet log of the node.
Observed behaviour
Freeze events on our clusters were announced about 15 minutes ahead, as 3-second pauses. About 295 seconds before the freeze, aks-auto-repair logs NodeCordonStart, NodeDrainStart, Evicted and NodeDrainEnd, the last three within the same second.
From the kubelet log of one eviction:
- The pod object was gone from the API 13 ms after the eviction.
- 1 second later, the kubelet logged
PreStop hook not completed in grace periodwithgracePeriod=1. - It then stopped the container with
gracePeriod=2, the kubelet's minimum, and thesleep 40process exited with code 137.
Normal pod deletions on the same node log gracePeriod=20, which is the 60 seconds of terminationGracePeriodSeconds minus the 40 seconds of preStop.
Across 3 clusters, from 8 to 19 October 2026, all 25 freeze evictions of this workload had a FailedPreStopHook event 0.5 to 2.8 seconds after the eviction. None of the 390 other terminations of the same workload in that period had one.
The clusters have no API server audit log, so we cannot see the grace period in the eviction request itself. From the kubelet log, it is 0 or 1 second.
Expected behavior
The eviction uses the pod's terminationGracePeriodSeconds, as kubectl drain and the Eviction API do by default. With the drain starting about 5 minutes before the freeze, a grace period of up to a few minutes would still finish before the pause.
If a short grace period is intentional, please document it on the evict-on-freeze page, and preferably make it configurable in remediator-config. Today the page only says that eviction happens about five minutes before the freeze and respects PodDisruptionBudgets.
Environment (please complete the following information):
- Kubernetes version: 1.36.2
- Node image: Azure Linux 3.0 (
AKSAzureLinux-V3gen2, 2026-07 to 2026-10 releases) - Region: West Europe
- Feature: evict-on-freeze (preview)
Additional context
Our workload is an ingress controller behind a load balancer. The preStop sleep keeps it serving while the load balancer takes the node out of rotation. Without that time, all open requests and WebSockets on the pod end abruptly, which is the disruption evict-on-freeze is meant to prevent.
@swgriffith, @wenjungaogaogao, @djsly would you be able to assist?
This issue has been automatically marked as stale because it has not had any activity for 30 days. It will be closed if no further activity occurs within 7 days of this comment. Please review @djsly, @wenjungaogaogao, @swgriffith.