|
| 1 | +Blue/green deployment to release multiple services simultaneously |
| 2 | +================================================================= |
| 3 | + |
| 4 | +> In this example, we release a new version of 2 services simultaneously using |
| 5 | +the blue/green deployment strategy. [Traefik](https://traefik.io) in used as |
| 6 | +Ingress controller, this example would also work with the |
| 7 | +[Nginx Ingress controller](https://github.com/kubernetes/ingress-nginx). |
| 8 | + |
| 9 | +## Steps to follow |
| 10 | + |
| 11 | +1. service a and b are serving traffic |
| 12 | +1. deploy new version of both services |
| 13 | +1. wait for all services to be ready |
| 14 | +1. switch incoming traffic from version 1 to version 2 |
| 15 | +1. shutdown version 1 |
| 16 | + |
| 17 | +## In practice |
| 18 | + |
| 19 | +Install the latest version of |
| 20 | +[Helm](https://docs.helm.sh/using_helm/#installing-helm), then install |
| 21 | +[Traefik](https://traefik.io/): |
| 22 | + |
| 23 | +```bash |
| 24 | +# Deploy Traefik with Helm |
| 25 | +$ helm install \ |
| 26 | + --name=traefik \ |
| 27 | + --version=1.60.0 \ |
| 28 | + --set rbac.enabled=true \ |
| 29 | + stable/traefik |
| 30 | + |
| 31 | +# Deploy version 1 of application a and b and the ingress |
| 32 | +$ kubectl apply -f app-a-v1.yaml -f app-b-v1.yaml -f ingress-v1.yaml |
| 33 | + |
| 34 | +# Test if the deployment was successful |
| 35 | +$ ingress=$(minikube service traefik --url | head -n1) |
| 36 | +$ curl $ingress -H 'Host: a.domain.com' |
| 37 | +Host: my-app-a-v1-66fb8d6f99-hs8jr, Version: v1.0.0 |
| 38 | + |
| 39 | +$ curl $ingress -H 'Host: b.domain.com' |
| 40 | +Host: my-app-b-v1-5766557f99-dpghc, Version: v1.0.0 |
| 41 | + |
| 42 | +# To see the deployment in action, open a new terminal and run the following |
| 43 | +# command |
| 44 | +$ watch kubectl get po |
| 45 | + |
| 46 | +# Then deploy version 2 of both applications |
| 47 | +$ kubectl apply -f app-a-v2.yaml -f app-b-v2.yaml |
| 48 | + |
| 49 | +# Wait for both applications to be running |
| 50 | +$ kubectl rollout status deploy my-app-a-v2 -w |
| 51 | +deployment "my-app-a-v2" successfully rolled out |
| 52 | + |
| 53 | +$ kubectl rollout status deploy my-app-b-v2 -w |
| 54 | +deployment "my-app-b-v2" successfully rolled out |
| 55 | + |
| 56 | +# Check the status of the deployment, then when all the pods are ready, you can |
| 57 | +# update the ingress |
| 58 | +$ kubectl apply -f ingress-v2.yaml |
| 59 | + |
| 60 | +# Test if the deployment was successful |
| 61 | +$ curl $ingress -H 'Host: a.domain.com' |
| 62 | +Host: my-app-a-v2-6b58d47c5f-nmzds, Version: v2.0.0 |
| 63 | + |
| 64 | +$ curl $ingress -H 'Host: b.domain.com' |
| 65 | +Host: my-app-b-v2-5c9dc59959-hp5kh, Version: v2.0.0 |
| 66 | + |
| 67 | +# In case you need to rollback to the previous version |
| 68 | +$ kubectl apply -f ingress-v1.yaml |
| 69 | + |
| 70 | +# If everything is working as expected, you can then delete the v1.0.0 |
| 71 | +# deployment |
| 72 | +$ kubectl delete -f ./app-a-v1.yaml -f ./app-b-v1.yaml |
| 73 | +``` |
| 74 | + |
| 75 | +### Cleanup |
| 76 | + |
| 77 | +```bash |
| 78 | +$ kubectl delete all -l app=my-app |
| 79 | +$ helm del --purge traefik |
| 80 | +``` |
0 commit comments