argo-rollouts结合Istio进行Canary流量迁移

 给default打标签,让pod自动注入istio sidecar

[root@master 08-argo-rollouts]# kubectl label namespace default istio-injection=enabled
namespace/default labeled
[root@master 08-argo-rollouts]# kubectl apply -f 02-argo-rollouts-with-istio-traffic-shifting.yaml 
rollout.argoproj.io/rollouts-helloworld-with-traffic-shifting created
service/spring-boot-helloworld unchanged
virtualservice.networking.istio.io/helloworld-rollout-vsvc created
destinationrule.networking.istio.io/helloworld-rollout-destrule created
[root@master 08-argo-rollouts]# cat 02-argo-rollouts-with-istio-traffic-shifting.yaml 
# CopyRight: MageEdu <mage@magedu.com>
---
apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata:
  name: rollouts-helloworld-with-traffic-shifting
spec:
  replicas: 10 
  strategy:
    canary:
      trafficRouting:
        istio:
          virtualService: 
            name: helloworld-rollout-vsvc        # required
            routes:
            - primary                 # optional if there is a single route in VirtualService, required otherwise
          destinationRule:
            name: helloworld-rollout-destrule    # required
            canarySubsetName: canary  # required
            stableSubsetName: stable  # required
      steps:
      - setCanaryScale:
          matchTrafficWeight: true
      - setWeight: 5
      - pause: {duration: 1m}
      - setWeight: 10
      - pause: {duration: 1m}
      - pause: {duration: 20}
      - setWeight: 20
      - pause: {duration: 40}
      - 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
---
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: helloworld-rollout-vsvc
spec:
  #gateways:
  #- istio-rollout-gateway
  hosts:
  - spring-boot-helloworld
  http:
  - name: primary       # referenced in canary.trafficRouting.istio.virtualService.routes
    route:
    - destination:
        host: spring-boot-helloworld
        subset: stable  # referenced in canary.trafficRouting.istio.destinationRule.stableSubsetName
      weight: 100
    - destination:
        host: spring-boot-helloworld
        subset: canary  # referenced in canary.trafficRouting.istio.destinationRule.canarySubsetName
      weight: 0
---
apiVersion: networking.istio.io/v1beta1
kind: DestinationRule
metadata:
  name: helloworld-rollout-destrule
spec:
  host: spring-boot-helloworld
  subsets:
  - name: canary   # referenced in canary.trafficRouting.istio.destinationRule.canarySubsetName
    labels:        # labels will be injected with canary rollouts-pod-template-hash value
      app: spring-boot-helloworld
  - name: stable   # referenced in canary.trafficRouting.istio.destinationRule.stableSubsetName
    labels:        # labels will be injected with stable rollouts-pod-template-hash value
      app: spring-boot-helloworld
---
[root@master 08-argo-rollouts]# kubectl get vs
NAME                      GATEWAYS   HOSTS                        AGE
helloworld-rollout-vsvc              ["spring-boot-helloworld"]   15m

 

可以看到canary权重为0,stable权重为100

[root@master 08-argo-rollouts]# kubectl get vs helloworld-rollout-vsvc -o yaml -w
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"networking.istio.io/v1beta1","kind":"VirtualService","metadata":{"annotations":{},"name":"helloworld-rollout-vsvc","namespace":"default"},"spec":{"hosts":["spring-boot-helloworld"],"http":[{"name":"primary","route":[{"destination":{"host":"spring-boot-helloworld","subset":"stable"},"weight":100},{"destination":{"host":"spring-boot-helloworld","subset":"canary"},"weight":0}]}]}}
  creationTimestamp: "2022-11-14T02:02:32Z"
  generation: 1
  name: helloworld-rollout-vsvc
  namespace: default
  resourceVersion: "1613040"
  uid: e5e693fd-0b56-4e2a-b386-78a3a010230d
spec:
  hosts:
  - spring-boot-helloworld
  http:
  - name: primary
    route:
    - destination:
        host: spring-boot-helloworld
        subset: stable
      weight: 100
    - destination:
        host: spring-boot-helloworld
        subset: canary
      weight: 0

访问测试都是旧版本0.9.2

把image版本改成0.9.3,再apply

[root@master 08-argo-rollouts]# 02-argo-rollouts-with-istio-traffic-shifting.yaml 
    spec:
      containers:
      - name: spring-boot-helloworld
        image: ikubernetes/spring-boot-helloworld:v0.9.3
[root@master 08-argo-rollouts]# kubectl apply -f 02-argo-rollouts-with-istio-traffic-shifting.yaml 
rollout.argoproj.io/rollouts-helloworld-with-traffic-shifting configured
service/spring-boot-helloworld unchanged
virtualservice.networking.istio.io/helloworld-rollout-vsvc unchanged
destinationrule.networking.istio.io/helloworld-rollout-destrule configured

第一次权重是5,第二次权重是10

全部更新完

posted @ 2022-11-14 10:39  Maniana  阅读(118)  评论(0编辑  收藏  举报