PreStopHookError
KubernetesWARNINGCriticalContainer ErrorHIGH confidence

preStop hook failed during pod termination

Production Risk

Graceful shutdown may be incomplete; in-flight requests may be dropped or queues not flushed.

What this means

PreStopHookError occurs when the preStop lifecycle hook fails or times out during pod termination. Unlike postStart, a preStop failure does not prevent the container from being killed — Kubernetes continues with termination regardless. However, a failing preStop hook means graceful shutdown logic (flushing queues, deregistering from service discovery) was not executed.

Why it happens
  1. 1preStop exec command exits with non-zero code
  2. 2preStop HTTP endpoint returns an error
  3. 3preStop hook takes longer than terminationGracePeriodSeconds
How to reproduce

Observed in events during pod deletion; may cause incomplete graceful shutdown.

trigger — this will error
trigger — this will error
kubectl describe pod mypod | grep -i "prestop|lifecycle"
kubectl get events --field-selector involvedObject.name=mypod | grep -i prestop

expected output

Warning  FailedPreStopHook  ...  Exec lifecycle hook failed

Fix

Ensure preStop command is idempotent and fast

WHEN preStop hook is failing or timing out

Ensure preStop command is idempotent and fast
lifecycle:
  preStop:
    exec:
      command: ["/bin/sh", "-c", "sleep 5"]
# Increase grace period if hook needs more time
terminationGracePeriodSeconds: 60

Why this works

A simple sleep in preStop gives load balancers time to deregister the pod before shutdown.

Sources
Official documentation ↗

Kubernetes Documentation

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All Kubernetes errors