Blue-green release
Blue-green deployments are kept the old version, the new version to deploy and then test to confirm flow will gradually cut OK to the new version. Blue, green and deployment without downtime and less risk.
Examples
This embodiment is an application nginx, comprising a deployment, service and ingress. deployment of foreign exposure by NodePort port, and there is a ingress of external services. Layout template below.
Example Project Address: https://code.aliyun.com/CodePipeline/kubernetes-deploy-demo.git
Application of a deployed version (old-nginx) Step 1
Layout template as follows:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: old-nginx
spec:
replicas: 2
selector:
matchLabels:
run: old-nginx
template:
metadata:
labels:
run: old-nginx
spec:
containers:
- image: registry.cn-hangzhou.aliyuncs.com/xianlu/old-nginx
imagePullPolicy: Always
name: old-nginx
ports:
- containerPort: 80
protocol: TCP
restartPolicy: Always
apiVersion: v1
kind: Service
metadata:
name: old-nginx
spec:
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
run: old-nginx
sessionAffinity: None
type: NodePort
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: gray-release
spec:
rules:
- host: www.example.com
http:
paths:
- path: /
backend:
serviceName: old-nginx
servicePort: 80
Configuration CodePipeline project deployment:
Log Master node, Ingress query access address
NAME HOSTS ADDRESS PORTS AGE
gray-release www.example.com 47.97.238.11 80 8m
Execute curl command to check the routing of access:
#curl -H "Host: www.example.com" http://47.97.238.11
old
Step two to create a new version of the application (new-nginx)
Layout template as follows:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: new-nginx
spec:
replicas: 1
selector:
matchLabels:
run: new-nginx
template:
metadata:
labels:
run: new-nginx
spec:
containers:
- image: registry.cn-hangzhou.aliyuncs.com/xianlu/new-nginx
imagePullPolicy: Always
name: new-nginx
ports:
- containerPort: 80
protocol: TCP
restartPolicy: Always
apiVersion: v1
kind: Service
metadata:
name: new-nginx
spec:
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
run: new-nginx
sessionAffinity: None
type: NodePort
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: gray-release
annotations:
# 请求头中满足正则匹配foo=bar的请求才会被路由到新版本服务new-nginx中
#nginx.ingress.kubernetes.io/service-match: |
# new-nginx: header("foo", /^bar$/)
nginx.ingress.kubernetes.io/service-weight: |
new-nginx: ${NEW_PER}, old-nginx: ${OLD_PER}
spec:
rules:
- host: www.example.com
http:
paths:
- path: /
backend:
serviceName: old-nginx
servicePort: 80
- path: /
backend:
serviceName: new-nginx
servicePort: 80
Here we set the $ {NEW_PER} and $ {OLD_PER} two environment variables in layout templates to help regulate the routing weight. You can set the proportion of blue-green traffic issued by the flexibility to adjust these two values.
Configuration CodePipeline project deployment:
NEW_PER set to 0, OLD_PER 100 is deployed:
Execute curl command to check the routing of access:
#curl -H "Host: www.example.com" http://47.97.238.11
old
#curl -H "Host: www.example.com" http://47.97.238.11
old
#curl -H "Host: www.example.com" http://47.97.238.11
old
Set NEW_PER to 50, OLD_PER 50 for deployment:
Execute curl command to check the routing of access:
#curl -H "Host: www.example.com" http://47.97.238.11
old
#curl -H "Host: www.example.com" http://47.97.238.11
old
#curl -H "Host: www.example.com" http://47.97.238.11
old
#curl -H "Host: www.example.com" http://47.97.238.11
new
#curl -H "Host: www.example.com" http://47.97.238.11
new
#curl -H "Host: www.example.com" http://47.97.238.11
old
NEW_PER set to 100, OLD_PER deployed to 0:
Execute curl command to check the routing of access:
#curl -H "Host: www.example.com" http://47.97.238.11
new
#curl -H "Host: www.example.com" http://47.97.238.11
new
#curl -H "Host: www.example.com" http://47.97.238.11
new
#curl -H "Host: www.example.com" http://47.97.238.11
new
After the completion of the new test version of the application, you can Ingress routing weight to 100 will flow entirely new service-oriented; or delete Ingress in annotations and the old version of the service, to achieve blue-green publishing.
Gray release
It refers to a gradation release release manner between black and white, can be a smooth transition. Let some users continue to use the A, B began to use part of the user, if the user does not have any objections to B, then gradually expand the scope, all users are migrated to the B to the top.
If we want to meet the request header foo = bar client requests can be routed to the new version of the service (new-nginx), then we can modify the configuration ingress rule as follows:
Layout template as follows:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: new-nginx
spec:
replicas: 1
selector:
matchLabels:
run: new-nginx
template:
metadata:
labels:
run: new-nginx
spec:
containers:
- image: registry.cn-hangzhou.aliyuncs.com/xianlu/new-nginx
imagePullPolicy: Always
name: new-nginx
ports:
- containerPort: 80
protocol: TCP
restartPolicy: Always
apiVersion: v1
kind: Service
metadata:
name: new-nginx
spec:
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
run: new-nginx
sessionAffinity: None
type: NodePort
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: gray-release
annotations:
# 请求头中满足正则匹配foo=bar的请求才会被路由到新版本服务new-nginx中
nginx.ingress.kubernetes.io/service-match: |
new-nginx: header("foo", /^bar$/)
spec:
rules:
- host: www.example.com
http:
paths:
- path: /
backend:
serviceName: old-nginx
servicePort: 80
- path: /
backend:
serviceName: new-nginx
servicePort: 80
Configuration CodePipeline project deployment:
Execute curl command to check the routing of access:
#curl -H "Host: www.example.com" http://47.97.238.11
old
#curl -H "Host: www.example.com" http://47.97.238.11
old
#curl -H "Host: www.example.com" http://47.97.238.11
old
#curl -H "Host: www.example.com" -H "foo: bar" http://47.97.238.11
new
#curl -H "Host: www.example.com" -H "foo: bar" http://47.97.238.11
new
#curl -H "Host: www.example.com" -H "foo: bar" http://47.97.238.11
new
Source: https: //help.aliyun.com/knowledge_detail/85948.html