argo-rollout使用--金丝雀部署

发布时间 2024-01-12 16:01:51作者: 少年老余

金丝雀部署

说明:按比例进行发布, 灰度发布。 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
View Code

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
      - 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%

 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