In this exercise we're going to see how blue-green deployments work in Kubernetes using only its primitives.
-
Let's create our deploy and expose it with a NodePort service. Be sure to examine the manifests first!
kubectl apply -f deploy-v1.yaml kubectl apply -f service-v1.yaml
-
You can now call the application using localhost on port
30080
:curl localhost:30080
-
We want to change the image from
httpd:alpine
tonginx:alpine
, and we want this change to happen instantly.Let's create a new deployment definition, with the following requirements:
- name:
beautiful-v2
- image:
nginx:alpine
- replicas:
4
- labels:
app=beautiful,version=v2
And let's also apply it to our cluster, waiting for all the pods to be running.
You can use the
v1
definition and change it accordingly, but be sure not to delete thev1
deployment! - name:
-
You can try to call the application again and get the same response as before.
curl localhost:30080
Why is that? Well, because our Service is still routing traffic to the
v1
application! -
So, let's update the service definition.
Change the Service selector from
version=v1
toversion=v2
.You can use the
kubectl edit
command or edit the manifest and apply it again. -
Let's call the application one last time.
curl localhost:30080
What is the response? Has it changed?
-
We don't need the
v1
deployment anymore, let's scale it down.kubectl scale deploy beautiful-v1 --replicas=0
-
Finally, you can cleanup everything.
kubectl delete deployment beautiful-v1 beautiful-v2 kubectl delete service beautiful