金丝雀部署
说明:按比例进行发布, 灰度发布。 30%, 60%, 100%
官网:https://argoproj.github.io/argo-rollouts/features/canary/
1.application部署
kubectl apply -f application.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/金丝雀部署
repoURL: https://gitee.com/arionyu/k8syaml.git
targetRevision: HEAD
syncPolicy:
automated: {}
syncOptions:
- CreateNamespace=true
2.rollout.yaml准备放到git上,
apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata:
name: example-rollout
spec:
replicas: 10
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.21.1
ports:
- containerPort: 80
imagePullSecrets:
- name: aliharbor
minReadySeconds: 30
revisionHistoryLimit: 3
strategy:
canary: #Indicates that the rollout should use the Canary strategy
maxSurge: "25%"
maxUnavailable: 0
steps:
- setWeight: 10 #第一次更新百分之十
- pause:
duration: 1h # 1 hour ,可以等待1h,自动更新20%
- setWeight: 20 #第二次更新百分之十,加第一次共更新百分之二十
- pause: {} # pause indefinitely 无限期暂停,需要手动执行下一步
- setWeight: 60
- pause: {}
3.执行SYNC
4.更新镜像
kubectl argo rollouts set image -n argo-rollouts example-rollout nginx=registry.cn-hangzhou.aliyuncs.com/yushihao/nginx
发布10% pod
继续手动切换,共发布20%; 自动发布, 需要等待1h
kubectl argo rollouts promote -n argo-rollouts example-rollout
发布60%:kubectl argo rollouts promote -n argo-rollouts example-rollout
发布100%:kubectl argo rollouts promote -n argo-rollouts example-rollout