k8s各种蓝绿及金丝雀发布

目前Kubernetes Gateway API并没有特别好的选型方案

最好能使用API Gateway来进行流量控制

各网关进度:

https://gateway-api.sigs.k8s.io/implementations/

使用原生集群完成灰度

Ps.无需安装其他工具

使用apisix-ingress可以使灰度颗粒度更细

可通过jenkins pipeline 控制流水线

image-20220615154947248

argo-rollout

Ps 需要将原有dep 文件 api 更换为 argo 的rollouts

官方文档: https://argoproj.github.io/argo-rollouts/

安装

1
2
kubectl create namespace argo-rollouts
kubectl apply -n argo-rollouts -f https://github.com/argoproj/argo-rollouts/releases/latest/download/install.yaml

Rollout 对象 其实就是一个自定义的Deployments ,由其spec.strategy控制其更新

官方案例1

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
# This example demonstrates a Rollout using the blue-green update strategy, which contains a manual
# gate before promoting the new stack.
apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata:
name: rollout-bluegreen
spec:
replicas: 2
revisionHistoryLimit: 2
selector:
matchLabels:
app: rollout-bluegreen
template:
metadata:
labels:
app: rollout-bluegreen
spec:
containers:
- name: rollouts-demo
image: nginx:1.7.9
imagePullPolicy: Always
ports:
- containerPort: 8080
strategy:
blueGreen:
# activeService specifies the service to update with the new template hash at time of promotion.
# This field is mandatory for the blueGreen update strategy.
activeService: rollout-bluegreen-active
# previewService specifies the service to update with the new template hash before promotion.
# This allows the preview stack to be reachable without serving production traffic.
# This field is optional.
previewService: rollout-bluegreen-preview
# autoPromotionEnabled disables automated promotion of the new stack by pausing the rollout
# immediately before the promotion. If omitted, the default behavior is to promote the new
# stack as soon as the ReplicaSet are completely ready/available.
# Rollouts can be resumed using: `kubectl argo rollouts promote ROLLOUT`
autoPromotionEnabled: false #这里控制是否手动控制更新进度
# kubectl-argo-rollouts promote rollout-bluegreen 这个可以继续更新

---
kind: Service
apiVersion: v1
metadata:
name: rollout-bluegreen-active
spec:
selector:
app: rollout-bluegreen
ports:
- protocol: TCP
port: 80
targetPort: 8080

---
kind: Service
apiVersion: v1
metadata:
name: rollout-bluegreen-preview
spec:
selector:
app: rollout-bluegreen
ports:
- protocol: TCP
port: 80
targetPort: 8080

以这个例子为例

修改镜像触发更新

如果没有使用Rollout,那么如果应用正在更新中,rollout-bluegreen-activerollout-bluegreen-preview两个svc访问的效果是一样的

但是如果使用了Rollout,那么rollout-bluegreen-active svc 将会提供稳定版本(应用没有更新前的版本)

rollout-bluegreen-preview将会提供正在更新中的应用版本(新创建的应用版本),更新过程中会自动将旧的pod ip 替换为新的

官方金丝雀实例

flagger

生态全,比较重

Flux2 才支持apisix 且没GA