Docker image for Codefresh Pipeline Step to Execute Blue/Green Deployment
2.3K
This repository holds a bash script that allows you to perform blue/green deployments on a Kubernetes cluster. See also the respective blog post
The script expects you to have an existing deployment and service on your K8s cluster. It does the following:
Of course during the wait period when both deployments are active, you are free to run your own additional checks or integration tests to see if the new deployment is ok.
The script needs one environment variable called KUBE_CONTEXT that selects the K8s cluster that will be used (if you have more than one)
The rest of the parameters are provided as command line arguments
| Parameter | Argument Number | Description |
|---|---|---|
| Service | 1 | Name of the existing service |
| Deployment | 2 | Name of the existing deployment |
| New version | 3 | Tag of the new docker image |
| Health command | 4 | Currently unused |
| Health seconds | 5 | Time where both deployments will co-exist |
| Namespace | 6 | Kubernetes namespace that will be used |
Here is an example:
./k8s-blue-green.sh myService myApp 73df943 true 30 my-namespace
In order for the script to work, your service and deployment should have a version label that is used as a selector.
This is what the script is using to detect the current version and in order to deploy the next one.
You can see examples of the tags with the sample application:
The script also comes with a Dockerfile that allows you to use it as a Docker image in any Docker based workflow such as Codefresh.
For the KUBE_CONTEXT environment variable just use the name of your cluster as found in the Codefresh Kubernetes dashboard. For the rest of the arguments you need to define them as parameters in your codefresh.yml file.
blueGreenDeploy:
title: "Deploying new version ${{CF_SHORT_REVISION}}"
image: codefresh/k8s-blue-green:master
environment:
- SERVICE_NAME=trivial
- DEPLOYMENT_NAME=trivial
- NEW_VERSION=${{CF_SHORT_REVISION}}
- HEALTH_SECONDS=30
- NAMESPACE=colors
- KUBE_CONTEXT=myDemoAKSCluster
The CF_SHORT_REVISION variable is offered by Codefresh and contains the git hash of the version that was just pushed. See all variables in the official documentation
The blue/green step is now deployed in dockerhub as well
https://hub.docker.com/r/codefresh/k8s-blue-green/
Further improvements
Content type
Image
Digest
Size
56.1 MB
Last updated
over 7 years ago
docker pull codefresh/k8s-blue-green:master