k8s实现最简单灰度发布

灰度发布又名金丝雀部署,是让部分用户访问到新版本应用,在 Kubernetes 中,可以使用两个具有相同 Pod 标签的 Deployment 来实现金丝雀部署。新版本的副本和旧版本的一起发布。在一段时间后如果没有检测到错误,则可以扩展新版本的副本数量并删除旧版本的应用。

v1版本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
labels:
app: tomcat-test
name: tomcat-test-v1
namespace: test
spec:
minReadySeconds: 100
replicas: 4
revisionHistoryLimit: 5
selector:
matchLabels:
app: tomcat-test
version: v1
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
type: RollingUpdate
template:
metadata:
annotations:
initializer.kubernetes.io/lxcfs: 'true'
labels:
app: tomcat-test
version: v1
spec:
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: app
operator: In
values:
- tomcat-test
topologyKey: kubernetes.io/hostname
containers:
- env:
- name: HOST_IP
valueFrom:
fieldRef:
fieldPath: status.hostIP
- name: POD_NAME
value: tomcat-test
- name: version
value: v1
image: vnet01-harbor.sy.cn/test/tomcat-test:r-20200214_175535
imagePullPolicy: Always
livenessProbe:
httpGet:
path: /abc/check_health.jsp
port: 6080
initialDelaySeconds: 80
timeoutSeconds: 20
name: tomcat-test
readinessProbe:
httpGet:
path: /abc/check_health.jsp
port: 6080
initialDelaySeconds: 80
timeoutSeconds: 20
resources:
limits:
cpu: '2'
memory: 4096M
requests:
cpu: '1'
memory: 2048M
volumeMounts:
- mountPath: /data/logs
name: app-log
readOnly: false
nodeSelector:
apptype: memnode
terminationGracePeriodSeconds: 60
volumes:
- hostPath:
path: /var/lib/docker/logs/tomcat-test
name: app-log

v2版本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
labels:
app: tomcat-test
name: tomcat-test-v2
namespace: test
spec:
minReadySeconds: 100
replicas: 1
revisionHistoryLimit: 5
selector:
matchLabels:
app: tomcat-test
version: v2
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
type: RollingUpdate
template:
metadata:
annotations:
initializer.kubernetes.io/lxcfs: 'true'
labels:
app: tomcat-test
version: v2
spec:
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: app
operator: In
values:
- tomcat-test
topologyKey: kubernetes.io/hostname
containers:
- env:
- name: HOST_IP
valueFrom:
fieldRef:
fieldPath: status.hostIP
- name: POD_NAME
value: tomcat-test
- name: version
value: v2
image: vnet01-harbor.sy.cn/test/tomcat-test:r-20200319_101302
imagePullPolicy: Always
livenessProbe:
httpGet:
path: /abc/check_health.jsp
port: 6080
initialDelaySeconds: 80
timeoutSeconds: 20
name: tomcat-test
readinessProbe:
httpGet:
path: /abc/check_health.jsp
port: 6080
initialDelaySeconds: 80
timeoutSeconds: 20
resources:
limits:
cpu: '2'
memory: 4096M
requests:
cpu: '1'
memory: 2048M
volumeMounts:
- mountPath: /data/logs
name: app-log
readOnly: false
nodeSelector:
apptype: memnode
terminationGracePeriodSeconds: 60
volumes:
- hostPath:
path: /var/lib/docker/logs/tomcat-test
name: app-log

流量比就是4:1

Donate