Skip to content
This repository was archived by the owner on Nov 10, 2019. It is now read-only.

Commit 782c2ae

Browse files
metadata update
1 parent 3d444b4 commit 782c2ae

File tree

3 files changed

+118
-0
lines changed

3 files changed

+118
-0
lines changed

plugins/Blue-green-deploy/README.md

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# Kubernetes blue green deployments
2+
3+
This repository holds a bash script that allows you to perform blue/green deployments on a Kubernetes cluster.
4+
See also the respective [blog post](https://codefresh.io/kubernetes-tutorial/fully-automated-blue-green-deployments-kubernetes-codefresh/)
5+
6+
## Description
7+
8+
The script expects you to have an existing deployment and service on your K8s cluster. It does the following:
9+
10+
1. Finds the current deployment (by looking at the selector of the service)
11+
1. Copies the old deployment to a new one changing the Docker image to the new version
12+
1. Applies the new deployment on the cluster. At this point both deployments co-exist
13+
1. Waits for a configurable amount of seconds
14+
1. Checks the health of the new pods. If there are restarts, it considers the new deployment unhealthy. In that case it removes it and the cluster is unaffected by the deployment
15+
1. If the health is ok it switches the service to point to the new deployment
16+
1. It removes the old deployment
17+
18+
Of course during the wait period when both deployments are active, you are free to run your own additional
19+
checks or integration tests to see if the new deployment is ok.
20+
21+
## Prerequisites
22+
23+
As a convention the script expects
24+
25+
1. The name of your deployment to be $APP_NAME-$VERSION
26+
1. Your deployment should have a label that shows it version
27+
1. Your service should point to the deployment by using *both* a version and label
28+
29+
Notice that the new color deployment created by the script will follow the same conventions. This
30+
way each subsequent pipeline you run will work in the same manner.
31+
32+
You can see examples of the tags with the sample application:
33+
34+
* [service](example/service.yml)
35+
* [deployment](example/deployment.yml)
36+
37+
38+
## How to use the script on its own
39+
40+
The script needs one environment variable called `KUBE_CONTEXT` that selects the K8s cluster that will be used (if you have more than one)
41+
42+
The rest of the parameters are provided as command line arguments
43+
44+
| Parameter | Argument Number | Description |
45+
| ----------| --------------- | --------------- |
46+
| Service | 1 | Name of the existing service |
47+
| Deployment | 2 | Name of the existing deployment |
48+
| New version | 3 | Tag of the new docker image |
49+
| Health command | 4 | Currently unused |
50+
| Health seconds | 5 | Time where both deployments will co-exist |
51+
| Namespace | 6 | Kubernetes namespace that will be used |
52+
53+
Here is an example:
54+
55+
```
56+
./k8s-blue-green.sh myService myApp 73df943 true 30 my-namespace
57+
```
58+
59+
60+
61+
## How to do Blue/Green deployments in Codefresh
62+
63+
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.
64+
65+
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](example/codefresh.yml) file.
66+
67+
```
68+
blueGreenDeploy:
69+
title: "Deploying new version ${{CF_SHORT_REVISION}}"
70+
image: codefresh/k8s-blue-green:master
71+
environment:
72+
- SERVICE_NAME=my-demo-app
73+
- DEPLOYMENT_NAME=my-demo-app
74+
- NEW_VERSION=${{CF_SHORT_REVISION}}
75+
- HEALTH_SECONDS=60
76+
- NAMESPACE=colors
77+
- KUBE_CONTEXT=myDemoAKSCluster
78+
```
79+
80+
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](https://codefresh.io/docs/docs/codefresh-yaml/variables/)
81+
82+
## Dockerhub
83+
The blue/green step is now deployed in dockerhub as well
84+
85+
https://hub.docker.com/r/codefresh/k8s-blue-green/
86+
87+
88+
## Future work
89+
90+
Further improvements
91+
92+
* Make the script create an initial deployment/service if nothing is deployed in the kubernetes cluster
93+
* Add more complex and configurable healthchecks
94+
95+
96+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
blueGreenDeploy:
2+
title: Deploying new version ${{CF_SHORT_REVISION}}
3+
image: codefresh/k8s-blue-green:master
4+
environment:
5+
- SERVICE_NAME=my-demo-app
6+
- DEPLOYMENT_NAME=my-demo-app
7+
- NEW_VERSION=${{CF_SHORT_REVISION}}
8+
- HEALTH_SECONDS=60
9+
- NAMESPACE=colors
10+
- KUBE_CONTEXT=myDemoAKSCluster

plugins/Blue-green-deploy/plugin.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
title: Blue/Green Deploy
2+
image: codefresh/k8s-blue-green:master
3+
description: Perform blue/green deployments on a Kubernetes cluster
4+
category:
5+
- Featured
6+
source: 'https://github.com/codefresh-io/k8s-blue-green-deployment'
7+
logo: 'https://raw.githubusercontent.com/codefresh-io/plugins/new-pipeline/plugins/vault/logo.jpg'
8+
maintainers:
9+
- name: Kostis Kapelonis
10+
envs:
11+
- name: KUBE_CONTEXT
12+
description: The name of your cluster (as found in the Codefresh Kubernetes dashboard).

0 commit comments

Comments
 (0)