备考ICA----Istio实验3---Istio DestinationRule 实验

备考ICA----Istio实验3---Istio DestinationRule 实验

1. hello服务说明

这部分服务沿用Istio实验2的deployment和svc

同时在上一个实验的deployment中分别加入了2个标签:

app: helloworld 两个deployment共有

version: v1 和 version: v2 两个deploymen 不同

详见:https://blog.csdn.net/qq_29974229/article/details/1369144651. 部署helloworld app 部分yaml内容

2. DestinationRule流量转发

2.1 通过DestinationRule将所有流量都转发到v1版本

2.1.1 配置文件

通过DestinationRule 将version: v1和version: v2分别定义成2个subnet,名字为v1和v2,随后在vs的destination中通过subset选择,定义weight权重来实现不同流量权重的分发.金丝雀发布就是通过这种方式来实现的

helloworld-dr-all-v1.yaml

yaml 复制代码
---
apiVersion: networking.istio.io/v1beta1
kind: DestinationRule
metadata:
  name: helloworld-destination
spec:
  host: helloworld
  subsets:
  - name: v1
    labels:
      version: v1
  - name: v2
    labels:
      version: v2
---
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: helloworld
spec:
  hosts:
  - "*"
  gateways:
  - helloworld-gateway
  http:
  - match:
    - uri:
        exact: /hello
    route:
    - destination:
        host: helloworld
        port:
          number: 5000
        subset: v1

应用配置

bash 复制代码
kubectl apply -f helloworld-dr-all-v1.yaml 

2.1.2 访问测试

即使在SVC上看到有v2的ep,但由于Envoy SideCar的存在,经由Istio Ingressgateway所有的流量直接被截获,并直接转发给了v1的vs由它响应请求

bash 复制代码
for i in {1..20};do curl http://192.168.126.220/hello ;sleep .5 ;done

2.2 通过 DestinationRule将流量2,8开给v1和v2

2.2.1 配置文件

之前已经在DestinationRule上定义了2个subnet,这里只需要定义vs的比例就可以了

helloworld-dr-20-v1.yaml

yaml 复制代码
---
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: helloworld
spec:
  hosts:
  - "*"
  gateways:
  - helloworld-gateway
  http:
  - match:
    - uri:
        exact: /hello
    route:
    - destination:
        host: helloworld
        port:
          number: 5000
        subset: v1
      weight: 20
    - destination:
        host: helloworld
        port:
          number: 5000
        subset: v2
      weight: 80
bash 复制代码
kubectl apply -f helloworld-dr-20-v1.yaml

2.2.2 访问测试

20个请求4次,显然和我们预期是一样的

bash 复制代码
for i in {1..20};do curl http://192.168.126.220/hello ;sleep .5 ;done


相关推荐
小猿姐2 小时前
唯品会大规模数据库云原生实践:基于 KubeBlocks 管理数千实例的统一运维之路
运维·elasticsearch·云原生
阿里云云原生13 小时前
AgentTeams 和 Claude Tag 都进入群聊模式,是新范式还是新叙事?
云原生·agent
阿里云云原生2 天前
Higress v2.2.3 发布:正式入驻 CNCF Sandbox,AI Gateway 与 Ingress 迁移能力双向加固
云原生
阿里云云原生2 天前
香港站【企业 AI Agent 工程化实战专场】来啦,邀您7月9日见!
云原生·agent
阿里云云原生3 天前
研发域与运维域的“数字握手”:通过 Agentic Skills 实现 DevOps 全链路自动化
云原生
阿里云云原生6 天前
AI 开发新常态:当 Cursor、Claude、Codex 并行,如何统一管理散落的 Skill 资产?
云原生·ai编程
探索云原生7 天前
K8s 1.36 这个 GA 特性,把 initContainer 拉模型的 hack 干掉了
ai·云原生·kubernetes
Java之美7 天前
从edge-trigger到level-trigger,谈谈 Kubernetes controller 的开发范式
云原生
阿里云云原生7 天前
深度解构:当 Append-only 的 SLS 遇上 Update/Delete,是如何实现设计权衡的?
云原生
Java之美8 天前
一次k8s升级引发的DevicePlugin注册失败
云原生·kubernetes