Appearance

Termination, disruption, and drain

Follow a Pod through shutdown and use a disruption budget to see when a node drain can proceed.

What you will understand

  • Explain how endpoint conditions and application shutdown affect established connections.
  • Predict which voluntary evictions a PodDisruptionBudget allows.
  • Interpret a blocked drain and identify capacity or readiness constraints before proceeding.

Builds on: DaemonSets, Jobs, and CronJobs

What happens while a Pod shuts down

You need to reboot a worker hosting one of three API Pods. The other copies should keep answering traffic and active requests on the affected Pod should have time to finish. Graceful termination is the period between a deletion request and the forced end of a Pod’s running processes. The kubelet gives containers time to shut down. If a preStop hook is configured and runs, it spends part of that same budget before the runtime sends the stop signal.

Meanwhile, EndpointSlices mark the endpoint as terminating and normally unready for new traffic. Changes take time to reach forwarding components, and existing connections can stay open. The application can stop accepting new requests and finish existing ones during the grace period. Step through both sides of termination in the scene and see why changing endpoint readiness cannot finish a request the app is already handling.

Who handles a request while a Pod shuts down?

Traffic changes and process shutdown overlap. The pod’s grace period bounds how long the app has to finish.

  1. API serverRecord deletion of the Pod
    EndpointSlice controller and kubeletThe routing update and shutdown begin asynchronously.
  2. KubeletRun preStop if configured
    ApplicationThe hook can begin draining within the shared grace period.
  3. Container runtimeSignal the running process
    ApplicationThe process can finish or close open requests before the deadline.
Follow the sequence

Traffic changes and process shutdown overlap. The pod’s grace period bounds how long the app has to finish.

One ordinary container and a normal deletion; precise propagation time depends on components.

Inspect the shutdown

Delete one web Pod behind a Service with another healthy backend. Follow endpoint changes in the control plane and shutdown on the worker node.

1 / 5

From kubectlTo API server

Start the termination grace period

The API server accepts the deletion and records the grace period and deletion timestamp. The Pod stays visible while its containers wind down.

Pod metadata.deletionTimestamp
Before
Unset
After
Set to the deletion deadline
Start the termination grace period

The API server accepts the deletion and records the grace period and deletion timestamp. The Pod stays visible while its containers wind down.

The diagram shows one possible order. Endpoint updates and kubelet shutdown run concurrently. No change to an EndpointSlice closes an established connection by itself.

Does preStop receive its own full timeout before the Pod’s grace period begins?
Reveal prediction answer

The countdown is already running when the hook starts. Time spent in preStop reduces the time left for the application to handle its stop signal.

Watch ready and terminating on the EndpointSlice while deleting the Pod. Compare the endpoint update with the time at which the Pod disappears.

Watch an endpoint during a real shutdown
Inspect YAML or commands

Exit before the deadline

terminationGracePeriodSeconds: 30
Explore another case

Open Inspect the shutdown to follow the deletion request, the EndpointSlice update, and the stop signal. The control plane can update the endpoint while the kubelet is still running the Pod’s shutdown hook.

Watch the endpoint while the Pod exits

Use the disposable kind lab cluster. This Pod’s preStop hook sleeps for 12 seconds so you have time to see the EndpointSlice change during its 25-second grace period.

kubectl --context kind-kv-lab get namespace kv-lab >/dev/null 2>&1 || \
  kubectl --context kind-kv-lab create namespace kv-lab
kubectl --context kind-kv-lab -n kv-lab apply -f - <<'YAML'
apiVersion: v1
kind: Pod
metadata:
  name: trace-shutdown
  labels:
    app: trace-shutdown
spec:
  terminationGracePeriodSeconds: 25
  containers:
    - name: web
      image: nginx:1.28.0-alpine
      lifecycle:
        preStop:
          exec:
            command: ["sleep", "12"]
---
apiVersion: v1
kind: Service
metadata:
  name: trace-shutdown
spec:
  selector:
    app: trace-shutdown
  ports:
    - port: 80
      targetPort: 80
YAML
kubectl --context kind-kv-lab -n kv-lab wait --for=condition=Ready \
  pod/trace-shutdown --timeout=90s

Start this watch and wait for READY=true and TERMINATING=false. Source lab-env.sh in both terminals so they use the same cluster.

kubectl --context kind-kv-lab -n kv-lab get endpointslices \
  -l kubernetes.io/service-name=trace-shutdown --watch \
  -o 'custom-columns=ADDRESS:.endpoints[*].addresses[*],READY:.endpoints[*].conditions.ready,TERMINATING:.endpoints[*].conditions.terminating'

Delete the Pod in the other terminal. Look for READY=false and TERMINATING=true while the Pod is still present. When it exits, its address disappears from the EndpointSlice. Stop the watch with Ctrl+C, then delete the Service.

kubectl --context kind-kv-lab -n kv-lab delete pod trace-shutdown --wait=false
kubectl --context kind-kv-lab -n kv-lab wait --for=delete \
  pod/trace-shutdown --timeout=60s
kubectl --context kind-kv-lab -n kv-lab delete service trace-shutdown

Keep enough replicas during maintenance

A PodDisruptionBudget (PDB) limits voluntary evictions performed through the Eviction API, such as those used by normal node drain. This example selects app: api in its own namespace and asks for two healthy copies to remain. If three matched Pods are healthy, the budget can allow one eviction. With only two healthy copies before the drain starts, evicting a healthy copy can be blocked until availability improves. Use the scene to try both cases.

apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
  name: api-availability
spec:
  minAvailable: 2
  selector:
    matchLabels:
      app: api

How does a disruption budget affect a drain?

A normal drain asks to evict eligible Pods and can advance when disruption is allowed and replacement capacity is available.

  1. OperatorCordon the node
    SchedulerOrdinary Pods are kept off the node for new placements.
  2. kubectl drainRequest an eviction
    Eviction APIThe current PodDisruptionBudget constrains the eviction.
  3. Workload controllerReplace the evicted replica
    Eligible workerThe replacement must fit and become healthy.
  4. Replacement PodReport readiness
    Disruption budgetRestored capacity can make another voluntary eviction possible.
Follow the sequence

A normal drain asks to evict eligible Pods and can advance when disruption is allowed and replacement capacity is available.

Three selected replicas with minAvailable=2; ordinary Eviction API path and a controller-managed workload.

Explore another case

Check the budget before draining the node

Cordon marks a node unschedulable for ordinary new Pods. Existing Pods remain. Drain requests eviction or deletion of eligible Pods and waits for them to terminate. A controller can create replacements, which need a suitable node and enough resources. In a disposable cluster, inspect the current and desired healthy counts and ALLOWED DISRUPTIONS before draining. Use a worker name from the cluster, and check application health before making it schedulable again.

kubectl get pdb api-availability
kubectl describe pdb api-availability
kubectl get pods -l app=api -o wide
# Only use a disposable worker obtained from kubectl get nodes.
kubectl cordon LAB_WORKER
kubectl drain LAB_WORKER --ignore-daemonsets
# After maintenance and health checks:
kubectl uncordon LAB_WORKER

Use the workload controllers lab to inspect a live disruption budget before trying a drain. To practice rescheduling a replica during maintenance, use a disposable cluster with a spare eligible worker.

Recognize disruptions the budget cannot prevent

A PDB cannot prevent a node crash. Direct Pod deletion can bypass the Eviction API, and a Deployment’s rollout follows its own update settings. If a drain is blocked, inspect unready Pods, the budget, and placement capacity before changing the procedure. Draining with --ignore-daemonsets leaves DaemonSet-managed Pods for the node’s system workload requirements.

Check your understanding

The budget needs two healthy replicas. Two are healthy and a third is pending because it cannot fit elsewhere. What should you fix before evicting a healthy replica?

Find enough eligible capacity for another replica and wait for it to become healthy. Then recheck the budget and the replacement plan. The budget is reporting that the workload cannot currently spare another healthy copy.

Primary documentation

Go to the source

Reviewed 2026-10-27 · Kubernetes 1.37 · Related local exercise

Search the book

Search loads when you open it.

Keyboard shortcuts

Ctrl + K / ⌘ + K
Search the book
?
Open this guide
Tab / Shift + Tab
Move between controls
Enter / Space
Activate a focused button or disclosure
← / →
Focused visual timeline · previous or next step
Home / End
Focused visual timeline · first or last point
Esc
Close the open dialog or menu