ArgoCD Rollouts - 结合Service进行Canary部署 【四】

实战案例1:结合Service进行Canary部署

#案例环境说明
    ◼ 应用:spring-boot-helloworld
        ◆微服务,默认监听于80/tcp
        ◆相关的path:/、/version和/hello
    ◼ 使用Argo Rollouts提供的Rollout资源编排运行该应用
        ◆使用Canary更新策略
        ◆推出一个Canary Pod后即暂停,需要用户手动Promote
#相关的常用命令
    ◼ 更新应用
        ◆kubectl argo rollouts set image ROLLOUT_NAME 
            CONTAINTER=NEW_IMAGE
    ◼ 继续更新
        ◆kubectl-argo-rollouts promote ROLLOUT_NAME [flags]
    ◼ 中止更新
        ◆kubectl-argo-rollouts abort ROLLOUT_NAME [flags]
    ◼ 回滚
        ◆kubectl-argo-rollouts undo ROLLOUT_NAME [flags]
[root@xianchaonode1 ~]# crictl pull  ikubernetes/spring-boot-helloworld:v0.9.2

[root@xianchaomaster1 08-argo-rollouts]# cat 01-argo-rollouts-demo.yaml
apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata:
  name: rollouts-spring-boot-helloworld
spec:
  replicas: 10
  strategy:
    canary:
      steps:
      - setWeight: 10
      - pause: {}
      - setWeight: 20
      - pause: {duration: 20}
      - setWeight: 30
      - pause: {duration: 20}
      - setWeight: 40
      - pause: {duration: 20}
      - setWeight: 60
      - pause: {duration: 20}
      - setWeight: 80
      - pause: {duration: 20}
  revisionHistoryLimit: 5
  selector:
    matchLabels:
      app: spring-boot-helloworld
  template:
    metadata:
      labels:
        app: spring-boot-helloworld
    spec:
      containers:
      - name: spring-boot-helloworld
        image: ikubernetes/spring-boot-helloworld:v0.9.2
        ports:
        - name: http
          containerPort: 80
          protocol: TCP
        resources:
          requests:
            memory: 32Mi
            cpu: 50m
        livenessProbe:
          httpGet:
            path: '/'
            port: 80
            scheme: HTTP
          initialDelaySeconds: 3
        readinessProbe:
          httpGet:
            path: '/'
            port: 80
            scheme: HTTP
          initialDelaySeconds: 5
---
apiVersion: v1
kind: Service
metadata:
  name: spring-boot-helloworld
spec:
  ports:
  - port: 80
    targetPort: http
    protocol: TCP
    name: http
  selector:
    app: spring-boot-helloworld

[root@xianchaomaster1 08-argo-rollouts]# kubectl apply -f 01-argo-rollouts-demo.yaml
rollout.argoproj.io/rollouts-spring-boot-helloworld created

#查看Dashboard情况

#查看命令行
[root@xianchaomaster1 08-argo-rollouts]# kubectl argo rollouts list rollouts
NAME                             STRATEGY   STATUS        STEP   SET-WEIGHT  READY  DESIRED  UP-TO-DATE  AVAILABLE
rollouts-spring-boot-helloworld  Canary     Healthy       12/12  100         10/10  10       10          10

[root@xianchaomaster1 08-argo-rollouts]# kubectl argo rollouts get rollouts rollouts-spring-boot-helloworld
Name:            rollouts-spring-boot-helloworld
Namespace:       default
Status:          ✔ Healthy
Strategy:        Canary
  Step:          12/12
  SetWeight:     100
  ActualWeight:  100
Images:          ikubernetes/spring-boot-helloworld:v0.9.2 (stable)
Replicas:
  Desired:       10
  Current:       10
  Updated:       10
  Ready:         10
  Available:     10

NAME                                                         KIND        STATUS     AGE    INFO
⟳ rollouts-spring-boot-helloworld                            Rollout     ✔ Healthy  4m34s
└──# revision:1
   └──⧉ rollouts-spring-boot-helloworld-55dd796d9c           ReplicaSet  ✔ Healthy  4m34s  stable
      ├──□ rollouts-spring-boot-helloworld-55dd796d9c-2kcwp  Pod         ✔ Running  4m34s  ready:1/1
      ├──□ rollouts-spring-boot-helloworld-55dd796d9c-4qw8r  Pod         ✔ Running  4m34s  ready:1/1
      ├──□ rollouts-spring-boot-helloworld-55dd796d9c-5nrmj  Pod         ✔ Running  4m34s  ready:1/1
      ├──□ rollouts-spring-boot-helloworld-55dd796d9c-5qfbm  Pod         ✔ Running  4m34s  ready:1/1
      ├──□ rollouts-spring-boot-helloworld-55dd796d9c-7nm29  Pod         ✔ Running  4m34s  ready:1/1
      ├──□ rollouts-spring-boot-helloworld-55dd796d9c-nr2pj  Pod         ✔ Running  4m34s  ready:1/1
      ├──□ rollouts-spring-boot-helloworld-55dd796d9c-ptxlv  Pod         ✔ Running  4m34s  ready:1/1
      ├──□ rollouts-spring-boot-helloworld-55dd796d9c-s7hn6  Pod         ✔ Running  4m34s  ready:1/1
      ├──□ rollouts-spring-boot-helloworld-55dd796d9c-smhnk  Pod         ✔ Running  4m34s  ready:1/1
      └──□ rollouts-spring-boot-helloworld-55dd796d9c-z6zh2  Pod         ✔ Running  4m34s  ready:1/1

 

 示例:更新镜像 查看效果

#执行更新镜像
crictl pull  ikubernetes/spring-boot-helloworld:v0.9.3

#执行更新命令
[root@xianchaomaster1 ~]# kubectl argo rollouts set image rollouts-spring-boot-helloworld spring-boot-helloworld=ikubernetes/spring-boot-helloworld:v0.9.3
rollout "rollouts-spring-boot-helloworld" image updated


#打开一个窗口进行监视
#这里先更新一个 就暂定了 可以通过界面继续或者命令行继续下面更新操作
#可以看到已经更新为Revision2  只更新一个 暂定了
[root@xianchaomaster1 08-argo-rollouts]# kubectl argo rollouts get rollouts rollouts-spring-boot-helloworld -w

NAME                                                         KIND        STATUS     AGE  INFO
⟳ rollouts-spring-boot-helloworld                            Rollout     ॥ Paused   10m
├──# revision:2
│  └──⧉ rollouts-spring-boot-helloworld-8548f55fb8           ReplicaSet  ✔ Healthy  40s  canary
│     └──□ rollouts-spring-boot-helloworld-8548f55fb8-r7gdb  Pod         ✔ Running  40s  ready:1/1
└──# revision:1
   └──⧉ rollouts-spring-boot-helloworld-55dd796d9c           ReplicaSet  ✔ Healthy  10m  stable
      ├──□ rollouts-spring-boot-helloworld-55dd796d9c-2kcwp  Pod         ✔ Running  10m  ready:1/1
      ├──□ rollouts-spring-boot-helloworld-55dd796d9c-4qw8r  Pod         ✔ Running  10m  ready:1/1
      ├──□ rollouts-spring-boot-helloworld-55dd796d9c-5nrmj  Pod         ✔ Running  10m  ready:1/1
      ├──□ rollouts-spring-boot-helloworld-55dd796d9c-5qfbm  Pod         ✔ Running  10m  ready:1/1
      ├──□ rollouts-spring-boot-helloworld-55dd796d9c-7nm29  Pod         ✔ Running  10m  ready:1/1
      ├──□ rollouts-spring-boot-helloworld-55dd796d9c-nr2pj  Pod         ✔ Running  10m  ready:1/1
      ├──□ rollouts-spring-boot-helloworld-55dd796d9c-ptxlv  Pod         ✔ Running  10m  ready:1/1
      ├──□ rollouts-spring-boot-helloworld-55dd796d9c-s7hn6  Pod         ✔ Running  10m  ready:1/1
      └──□ rollouts-spring-boot-helloworld-55dd796d9c-smhnk  Pod         ✔ Running  10m  ready:1/1

 

继续更新镜像操作

#打开一个终端测试访问请求
[root@xianchaomaster1 08-argo-rollouts]# kubectl run client-$RANDOM --image ikubernetes/admin-box:v1.2 --restart=Never -it --rm --command -- /bin/bash
If you don't see a command prompt, try pressing enter.
root@client-11797 /# while true; do curl spring-boot-helloworld/version; sleep .5;done
version 0.9.6!Spring Boot Helloworld, Version 0.9.3
Spring Boot Helloworld, Version 0.9.2
Spring Boot Helloworld, Version 0.9.2
Spring Boot Helloworld, Version 0.9.2
Spring Boot Helloworld, Version 0.9.2
Spring Boot Helloworld, Version 0.9.2
Spring Boot Helloworld, Version 0.9.2
Spring Boot Helloworld, Version 0.9.2
Spring Boot Helloworld, Version 0.9.2
Spring Boot Helloworld, Version 0.9.2
version 0.9.6!Spring Boot Helloworld, Version 0.9.3
Spring Boot Helloworld, Version 0.9.2
Spring Boot Helloworld, Version 0.9.2
Spring Boot Helloworld, Version 0.9.2


#执行命令 继续更新 使得Pause状态继续 或者管理端点击Promote
[root@xianchaomaster1 ~]# kubectl argo rollouts promote rollouts-spring-boot-helloworld
rollout 'rollouts-spring-boot-helloworld' promoted

#终端查看不断再更新 并且 流量比例也在变化
NAME                                                         KIND        STATUS     AGE  INFO
⟳ rollouts-spring-boot-helloworld                            Rollout     ॥ Paused   23m
├──# revision:2
│  └──⧉ rollouts-spring-boot-helloworld-8548f55fb8           ReplicaSet  ✔ Healthy  13m  canary
│     ├──□ rollouts-spring-boot-helloworld-8548f55fb8-r7gdb  Pod         ✔ Running  13m  ready:1/1
│     ├──□ rollouts-spring-boot-helloworld-8548f55fb8-lmwkq  Pod         ✔ Running  43s  ready:1/1
│     └──□ rollouts-spring-boot-helloworld-8548f55fb8-6g6g7  Pod         ✔ Running  13s  ready:1/1
└──# revision:1
   └──⧉ rollouts-spring-boot-helloworld-55dd796d9c           ReplicaSet  ✔ Healthy  23m  stable
      ├──□ rollouts-spring-boot-helloworld-55dd796d9c-2kcwp  Pod         ✔ Running  23m  ready:1/1
      ├──□ rollouts-spring-boot-helloworld-55dd796d9c-5nrmj  Pod         ✔ Running  23m  ready:1/1
      ├──□ rollouts-spring-boot-helloworld-55dd796d9c-5qfbm  Pod         ✔ Running  23m  ready:1/1
      ├──□ rollouts-spring-boot-helloworld-55dd796d9c-nr2pj  Pod         ✔ Running  23m  ready:1/1
      ├──□ rollouts-spring-boot-helloworld-55dd796d9c-ptxlv  Pod         ✔ Running  23m  ready:1/1
      ├──□ rollouts-spring-boot-helloworld-55dd796d9c-s7hn6  Pod         ✔ Running  23m  ready:1/1
      └──□ rollouts-spring-boot-helloworld-55dd796d9c-smhnk  Pod         ✔ Running  23m  ready:1/1


version 0.9.6!Spring Boot Helloworld, Version 0.9.3
Spring Boot Helloworld, Version 0.9.3
Spring Boot Helloworld, Version 0.9.3
Spring Boot Helloworld, Version 0.9.3
Spring Boot Helloworld, Version 0.9.2
Spring Boot Helloworld, Version 0.9.2
Spring Boot Helloworld, Version 0.9.2
Spring Boot Helloworld, Version 0.9.2
Spring Boot Helloworld, Version 0.9.2
Spring Boot Helloworld, Version 0.9.2
version 0.9.6!Spring Boot Helloworld, Version 0.9.3
Spring Boot Helloworld, Version 0.9.3
Spring Boot Helloworld, Version 0.9.3
Spring Boot Helloworld, Version 0.9.3
Spring Boot Helloworld, Version 0.9.2
Spring Boot Helloworld, Version 0.9.2
Spring Boot Helloworld, Version 0.9.2
Spring Boot Helloworld, Version 0.9.2
Spring Boot Helloworld, Version 0.9.2
Spring Boot Helloworld, Version 0.9.2
version 0.9.6!Spring Boot Helloworld, Version 0.9.3
Spring Boot Helloworld, Version 0.9.3
Spring Boot Helloworld, Version 0.9.3
Spring Boot Helloworld, Version 0.9.3
Spring Boot Helloworld, Version 0.9.2
Spring Boot Helloworld, Version 0.9.2
Spring Boot Helloworld, Version 0.9.2

#更新完成
Name:            rollouts-spring-boot-helloworld
Namespace:       default
Status:          ✔ Healthy
Strategy:        Canary
  Step:          12/12
  SetWeight:     100
  ActualWeight:  100
Images:          ikubernetes/spring-boot-helloworld:v0.9.3 (stable)
Replicas:
  Desired:       10
  Current:       10
  Updated:       10
  Ready:         10
  Available:     10

NAME                                                         KIND        STATUS        AGE    INFO
⟳ rollouts-spring-boot-helloworld                            Rollout     ✔ Healthy     26m
├──# revision:2
│  └──⧉ rollouts-spring-boot-helloworld-8548f55fb8           ReplicaSet  ✔ Healthy     16m    stable
│     ├──□ rollouts-spring-boot-helloworld-8548f55fb8-r7gdb  Pod         ✔ Running     16m    ready:1/1
│     ├──□ rollouts-spring-boot-helloworld-8548f55fb8-lmwkq  Pod         ✔ Running     3m43s  ready:1/1
│     ├──□ rollouts-spring-boot-helloworld-8548f55fb8-6g6g7  Pod         ✔ Running     3m13s  ready:1/1
│     ├──□ rollouts-spring-boot-helloworld-8548f55fb8-xdb7p  Pod         ✔ Running     2m43s  ready:1/1
│     ├──□ rollouts-spring-boot-helloworld-8548f55fb8-fg88l  Pod         ✔ Running     2m13s  ready:1/1
│     ├──□ rollouts-spring-boot-helloworld-8548f55fb8-wrdvr  Pod         ✔ Running     2m13s  ready:1/1
│     ├──□ rollouts-spring-boot-helloworld-8548f55fb8-d22mt  Pod         ✔ Running     103s   ready:1/1
│     ├──□ rollouts-spring-boot-helloworld-8548f55fb8-ncm7n  Pod         ✔ Running     103s   ready:1/1
│     ├──□ rollouts-spring-boot-helloworld-8548f55fb8-q6qxg  Pod         ✔ Running     73s    ready:1/1
│     └──□ rollouts-spring-boot-helloworld-8548f55fb8-vg9qb  Pod         ✔ Running     73s    ready:1/1
└──# revision:1
   └──⧉ rollouts-spring-boot-helloworld-55dd796d9c           ReplicaSet  • ScaledDown  26m

Spring Boot Helloworld, Version 0.9.3
Spring Boot Helloworld, Version 0.9.3
Spring Boot Helloworld, Version 0.9.3
Spring Boot Helloworld, Version 0.9.3
Spring Boot Helloworld, Version 0.9.3
Spring Boot Helloworld, Version 0.9.3
Spring Boot Helloworld, Version 0.9.3
Spring Boot Helloworld, Version 0.9.3
Spring Boot Helloworld, Version 0.9.3
version 0.9.6!Spring Boot Helloworld, Version 0.9.3
Spring Boot Helloworld, Version 0.9.3
Spring Boot Helloworld, Version 0.9.3
Spring Boot Helloworld, Version 0.9.3
Spring Boot Helloworld, Version 0.9.3
Spring Boot Helloworld, Version 0.9.3

可以看到 UI 上 继续更新 不断的切换流量比例

 

 

posted @ 2024-01-25 15:23  しみずよしだ  阅读(90)  评论(0)    收藏  举报