JAKUB KRZYWDA
@jakubkrzywda
How to perform
BLUE–GREEN DEPLOYMENTS
using only Kubernetes Primitives?
Trust me,
I’m a blue-green
parrot!
Blue–green deployment refers to running
two application environments in parallel
in a production cluster.
The first environment (blue) is running the
stable application version and the second
environment (green) is running the new
version.
By default, Kubernetes performs a rolling
update of a deployment.
The old version is replaced by the new
one during the rollout.
However, in case of some applications we
want to keep the old version “on stand-by”
for a while after the new rollout.
Luckily, it is possible to perform
blue–green deployments using only
Kubernetes primitives!
Here I show you how to do it in five easy
steps:
Create Blue Deployment
1.
replicas: 3
...
labels:
app: myapp
track: blue
image: myapp:v1
Create Blue Deployment
1.
Notice two labels, app
and track, their values
and the image tag.
replicas: 3
...
labels:
app: myapp
track: blue
image: myapp:v1
Expose it with a Service
2.
name: myservice
selector:
app: myapp
track: blue
replicas: 3
...
labels:
app: myapp
track: blue
image: myapp:v1
Expose it with a Service
2.
Service selector uses both labels –
app and track. Therefore, it precisely
matches the blue deployment!
name: myservice
selector:
app: myapp
track: blue
replicas: 3
...
labels:
app: myapp
track: blue
image: myapp:v1
Add an Ingress
3.
backend:
service: myservice
name: myservice
selector:
app: myapp
track: blue
replicas: 3
...
labels:
app: myapp
track: blue
image: myapp:v1
Add an Ingress
3.
backend:
service: myservice
Ingress is optional
but useful to
expose application
name: myservice
outside the cluster. selector:
app: myapp
track: blue
replicas: 3
...
labels:
app: myapp
track: blue
image: myapp:v1
Add Green Deployment
4.
backend:
service: myservice
name: myservice
selector:
app: myapp
track: blue
replicas: 3 replicas: 3
... ...
labels: labels:
app: myapp app: myapp
track: blue track: green
image: myapp:v1 image: myapp:v2
Add Green Deployment
4.
Notice different values backend:
of track label and service: myservice
image tag.
The number of replicas
is identical since the
name: myservice
green deployment selector:
should take over the app: myapp
whole workload. track: blue
replicas: 3 replicas: 3
... ...
labels: labels:
app: myapp app: myapp
track: blue track: green
image: myapp:v1 image: myapp:v2
Switch to Green Deployment
5.
backend:
service: myservice
name: myservice
selector:
app: myapp
track: green
replicas: 3 replicas: 3
... ...
labels: labels:
app: myapp app: myapp
track: blue track: green
image: myapp:v1 image: myapp:v2
Switch to Green Deployment
5.
backend:
service: myservice
Notice a new value of the
track service selector –
name: myservice
green. Therefore, the selector:
service matches only the app: myapp
track: green
green deployment now!
replicas: 3 replicas: 3
... ...
labels: labels:
app: myapp app: myapp
track: blue track: green
image: myapp:v1 image: myapp:v2
JAKUB KRZYWDA
@jakubkrzywda
THAT’S IT FOR TODAY!
My name is Jakub Krzywda.
I’m a Senior Cloud Native Engineer and
Kubernetes Trainer.
I post about: Kubernetes, Cloud Native
technologies and DevOps practices.
JAKUB KRZYWDA
@jakubkrzywda
WHAT DO YOU THINK?
Would you like to learn more about automation
tools for blue-green deployments in Kubernetes?
Remember
to click
follow + 🔔