1.金丝雀发布流程,安装比例发布,又名灰度发布
参考官网:https://argoproj.github.io/argo-rollouts/getting-started/nginx/
举例:共10pod
- 第一批发布 30%
- V1 : 10个Pod
- V2: 3个Pod
- 第二批发布 60%
- V1 : 10个Pod
- V2: 6个Pod
- 第三批发布 100%
- V1 : 10个Pod
- V2: 10个Pod
- 第四批发布
- V2: 10个Pod (active)
- V1: 0个Pod
2.资源文件准备
文件放到:https://gitee.com/arionyu/k8syaml.git
目录:argo/argo-rollout/金丝雀部署/ingresstest
ingress创建
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: demo-stable-ingress
namespace: argo-rollouts
annotations:
#kubernetes.io/ingress.class: nginx
acme.cert-manager.io/http01-edit-in-place: "true" #没有这个会导致All hosts are taken by other resources
spec:
ingressClassName: nginx
rules:
- host: yuqiao.test.com
http:
paths:
- backend:
service:
name: stable-service
port:
number: 80
path: /
pathType: Prefix
service创建
apiVersion: v1
kind: Service
metadata:
name: rollout-bluegreen-active
namespace: argo-rollouts
spec:
ports:
- nodePort: 30131
port: 80
protocol: TCP
targetPort: 80
selector:
app: rollout-bluegreen
sessionAffinity: None
type: NodePort
---
apiVersion: v1
kind: Service
metadata:
name: rollout-bluegreen-preview
namespace: argo-rollouts
spec:
ports:
- nodePort: 30132
port: 80
protocol: TCP
targetPort: 80
selector:
app: rollout-bluegreen
sessionAffinity: None
type: NodePort
rollout部署
apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata:
name: simple-rollout
spec:
replicas: 4
strategy:
canary:
canaryService: canary-service # required
stableService: stable-service # required
trafficRouting:
nginx:
# Either stableIngress or stableIngresses must be configured, but not both.
stableIngress: demo-stable-ingress
steps:
- setWeight: 30
- pause: {}
- setWeight: 60
- pause: {}
- setWeight: 100
- pause: {}
revisionHistoryLimit: 2
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
# image: nginx:1.21.1
image: registry.cn-hangzhou.aliyuncs.com/yushihao/nginx:latest
ports:
- name: http
containerPort: 80
protocol: TCP
imagePullSecrets:
- name: aliharbor
3.创建application,或者web创建
kubectl apply -f appliction.yaml
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: argo-rollouts
namespace: argocd
spec:
destination:
namespace: argo-rollouts
server: https://11.0.1.134:6443
project: default
source:
path: argo/argo-rollout/金丝雀部署/ingresstest
repoURL: https://gitee.com/arionyu/k8syaml.git
targetRevision: HEAD
syncPolicy:
automated: {}
syncOptions:
- CreateNamespace=true
创建app后
4.更新镜像发布 30%
修改rollout或者执行
kubectl argo rollouts set image -n argo-rollouts simple-rollout nginx=nginx:1.21.1
更新60%
kubectl argo rollouts promote simple-rollout -n argo-rollouts
更新100%
kubectl argo rollouts promote simple-rollout -n argo-rollouts
替换旧版本:
kubectl argo rollouts promote simple-rollout -n argo-rollouts
注意:
会自动创建金丝雀ingress,weight根据实际情况变更
疑问:
经过测试, 在没有到替换旧版本镜像后,流量一直走的旧镜像pod,怀疑因为ingress是nginx官网部署导致的,具体后期再测