给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

全部更新完

原文地址:http://www.cnblogs.com/zyyang1993/p/16888237.html

1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长! 2. 分享目的仅供大家学习和交流,请务用于商业用途! 3. 如果你也有好源码或者教程,可以到用户中心发布,分享有积分奖励和额外收入! 4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解! 5. 如有链接无法下载、失效或广告,请联系管理员处理! 6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需! 7. 如遇到加密压缩包,默认解压密码为"gltf",如遇到无法解压的请联系管理员! 8. 因为资源和程序源码均为可复制品,所以不支持任何理由的退款兑现,请斟酌后支付下载 声明:如果标题没有注明"已测试"或者"测试可用"等字样的资源源码均未经过站长测试.特别注意没有标注的源码不保证任何可用性