Video in progress

What is a blue-green deployment, and how does it differ from a rolling update?

In blue-green, the new version (green) is brought up fully next to the old one (blue), verified, and then all traffic is switched to it at once. A rolling update replaces pods one by one, and for a while both versions run mixed.

📖 Answer

In Kubernetes, the simple form is two Deployments and switching the Service selector:

# shop-api-blue  (version: blue)  - traffic goes here now
# shop-api-green (version: green) - the new version, being verified
apiVersion: v1
kind: Service
metadata:
  name: shop-api
spec:
  selector:
    app: shop-api
    version: green   # switched from "blue" to "green" - traffic moved

The advantage is very fast rollback: switch the selector back to blue and everything returns to the old state within seconds. Before the switch you can also run a smoke test against green through an internal URL.

The cost:

  • you need double the resources during the switch;
  • if there is a single DB, it must be compatible with both versions, and this constraint does not go away with blue-green;
  • long-lived connections (WebSocket) stay on blue, and you have to think about them separately.

When I choose it: when fast, full rollback matters and running the two versions mixed would cause trouble (for example, a cached format has changed). For most ordinary services a rolling update is enough.