Skip to content

Traffic and endpoints

A terminating pod is still an endpoint

Deleting a pod does not remove it from the service. It marks the endpoint not-ready and leaves it serving, and the gap between those two words is where the requests go.

about 11 minutes

Three booleans, and only one of them means what you think

You delete a pod with a thirty-second grace period. When does it stop appearing in the EndpointSlice?

Why the advice is a sleep

The standard fix is a preStop hook containing nothing but sleep. It looks like superstition and it is not. preStop runs before SIGTERM, so a sleep there delays the signal — and during that delay the application is untouched and answering exactly as it was a second ago.

What the sleep has to outlast is not the shutdown. It is the propagation: the time it takes every proxy to notice that this endpoint is no longer ready. A sleep shorter than that buys nothing at all, which is why a preStop of a tenth of a second — the version people write when they have heard the advice but not the reason — changes nothing.

And it only reaches pods created after it. The rollout that adds a preStop is never the rollout it protects; the one after it is.

The sleep does no work. That is the point: there is nothing to do except still be there while somebody else catches up.

Try this
apiVersion: apps/v1
kind: Deployment
metadata:
  name: checkout
spec:
  replicas: 3
  selector:
    matchLabels:
      app: checkout
  template:
    metadata:
      labels:
        app: checkout
    spec:
      terminationGracePeriodSeconds: 30
      containers:
      - name: api
        image: checkout:v1
        lifecycle:
          preStop:
            exec:
              command: ["sh","-c","sleep 5"]
When the container is actually signalled, against when the pod stopped being ready.
0ms simulated

Pods — in creation order

No pods. Nothing has been asked for, or nothing has acted yet.

Events — in the order the cluster produced them

No events yet.

Everything you do here stays in this browser.Part of liter8.sh