DEV Community

truc3651
truc3651

Posted on

Blue/green deployment with helm hands-on

QuickCap

Kubernetes uses RollingUpdate as the default deployment strategy, which transition to new version gradually.

Blue/green deployment strategy is about there're always 2 replica versions of application, this makes it easier to rollback to the previous version, if something goes wrong with the new release, and of course it's ideal for stateless application only.

Foreword

This post is about give you an overview picture of how blue/green deployment. There's no good practices, and re-use code well. If it's your thing, coninue reading :))

Resource

Clone repo: https://github.com/truc3651/devops

Quick look at the structure

Image description

Folder app contains everything for helm to release our app.
app/templates: where application template resident (deployment, config, secret, service)
app/Chart.yaml: release information (app name, version)
app/values.yaml: default environment variables that helm will use when install/upgrade app

deployment.sh: contains job visualize how blue/green deployment

Get your hands dirty

Install helm, kind
We use kind as local Kubernetes clusters.

brew install helm kind
Enter fullscreen mode Exit fullscreen mode

Create a default cluster

kind create cluster --name helm
Enter fullscreen mode Exit fullscreen mode

We have 1 control-plane
Image description

Change mod script

chmod +x ./deployment.sh
Enter fullscreen mode Exit fullscreen mode

First time deploy your application

./deployment.sh init
Enter fullscreen mode Exit fullscreen mode

We just create a deployment with 1 pod (default version blue)
Image description

At the beginning, service points to pod has label app=app
Image description

Release a new version
After weeks, your development team want to release new features.

./deployment.sh deploy-green
Enter fullscreen mode Exit fullscreen mode

You can see blue pod has been terminated, and a new green pod has been created, also green deployment created as well.
Image description

Now our service points to pod which has label color=green
Image description

Release a new version 3rd time
After many weeks, your team want to introduce bunch cool features

./deployment.sh deploy-new-blue
Enter fullscreen mode Exit fullscreen mode

This time, green pod has been terminated, and a new blue pod has been created.
Image description

And our service points to pod which has label color=blue
Image description

Rollback
The very new version has some critical bugs, so our team decides to rollback to the previous version

./deployment.sh rollback
Enter fullscreen mode Exit fullscreen mode

You can see now green alive
Image description

Top comments (0)