Blue-Green Deployments with Service Selectors
Blue-green needs no special tooling in Kubernetes. Run both versions as separate Deployments, point one Service at whichever should receive traffic, and cut over by patching the Service's selector. The switch is instant and complete, the rollback is the same command backwards, and the old version is still running the whole time.
Application Deployment Guide 17 of 44 Intermediate
- Kubernetes1.36.4
- Cluster4 nodes
- Runtimecontainerd 2.2.6
- CNICalico v3.32.1
- TimeAbout 14 min
A Service selector is plain equality on Pod labels, re-evaluated continuously by the endpoints controller. Patching it does not restart anything and does not touch either Deployment - the EndpointSlice is simply recomputed, typically within a second.
| Server Name | IP Address | OS | Roles | CPU | RAM | HDD |
|---|---|---|---|---|---|---|
| CKA1001 | 192.168.0.175 | Ubuntu 26.04 LTS | Control Plane Node | 2 Core | 4 GB | 50 GB |
| CKA1001-NODE01 | 192.168.0.176 | Ubuntu 26.04 LTS | Worker Node | 2 Core | 4 GB | 50 GB |
| CKA1001-NODE02 | 192.168.0.177 | Ubuntu 26.04 LTS | Worker Node | 2 Core | 4 GB | 50 GB |
| CKA1001-NODE03 | 192.168.0.178 | Ubuntu 26.04 LTS | Worker Node | 2 Core | 4 GB | 50 GB |
This guide includes
Use this when a release has to switch over instantly and roll back just as fast. This matters because blue-green needs no special tooling in Kubernetes - a Service selector is plain label equality, re-evaluated continuously, so one patch moves all of the traffic.
- running two versions at once, sharing one label and differing by another
- confirming the Service selects only one of them, and reading its EndpointSlice
- flipping the entire cutover with a single patch to the Service selector
- rolling back with that same patch and the old value
Before you start
- A cluster and kubectl.
- The session creates namespace
ckad-bgwith Deploymentsblueandgreen(two replicas each, serving different text), a Servicesiteselecting blue, and aclientPod.
-
Two versions running at once
-
The Service only sees one of them
-
Flip it
-
And back