Hard parts
Database migrations: expand and contract
Step through itYour pods can run two versions at once. Your database has only one schema. Any change v1 can't cope with breaks rolling, canary and blue-green alike, and makes rollback impossible. The fix is to break one risky change into several safe ones, so that every step works with the version before it.
You want to rename users.name to display_name. A single ALTER … RENAME would break every running pod at once.
- version
- v1
- reads
- name
- writes
- name
The shutdown race
When Kubernetes terminates a pod, two things start in parallel. The pod is removed from Service endpoints, and that change takes time to reach kube-proxy, ingresses and load balancers. Meanwhile the kubelet runs your preStop hook and then sends SIGTERM.
If the app exits on SIGTERM straight away, requests still in flight from slower load balancers hit a closed port. That shows up as a burst of 502s on every deploy. The fix:
- A short
preStopsleep (5–10s) while routing catches up. - On SIGTERM, stop accepting connections, finish in-flight requests, then exit.
terminationGracePeriodSecondslong enough for both. After it, SIGKILL.
Version skew
A browser loaded v1's JavaScript ten minutes ago. You deploy v2. That tab now calls v2's API, or requests a v1 asset that no longer exists. With rolling and canary releases this happens constantly, because requests from one user can land on either version.
Defences: keep APIs backwards compatible for at least one release, use content-hashed asset names, keep old assets around for a while, and send a version header so the server can tell the client to reload.
Sessions and long-lived connections
In-memory sessions
If a pod holds session state, replacing it logs users out. Move sessions to Redis or a signed cookie before you try any zero-downtime strategy.
WebSockets and gRPC streams
Connections stay pinned to old pods long after traffic shifts. Drain them politely: close them with a "reconnect" message during shutdown, and make sure clients reconnect with jitter.
Background jobs and queues
A v1 worker may pick up a message written by v2. Version your message formats, and let workers finish their current job before exiting.
Config is code
Feature-flag flips, config maps, firewall rules and content updates change behaviour just like a binary does, but they often skip the careful rollout. Several of the largest outages on record were configuration or content pushes that went everywhere at once (see Stories). Give config the same treatment as code: review it, stage it, canary it, and be able to revert it fast.
Rolling back vs rolling forward
Roll back
Return to the last known-good version. It's the fastest way to stop the bleeding, as long as nothing irreversible has happened since: a contracted schema, data written in a new format, or a message already sent to a third party.
Roll forward
Ship a fix on top. Sometimes it's the only option, but it's slower and riskier when you're under pressure. Design releases so rolling back stays possible for as long as you can, and make the point of no return a deliberate, separate step.