备考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/136914465 的 [1. 部署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

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

应用配置

kubectl apply -f helloworld-dr-all-v1.yaml 

在这里插入图片描述

2.1.2 访问测试

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

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

---
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
kubectl apply -f helloworld-dr-20-v1.yaml

2.2.2 访问测试

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

for i in {1..20};do curl http://192.168.126.220/hello ;sleep .5 ;done

在这里插入图片描述
在这里插入图片描述

相关推荐

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-03-25 19:38:05       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-03-25 19:38:05       100 阅读
  3. 在Django里面运行非项目文件

    2024-03-25 19:38:05       82 阅读
  4. Python语言-面向对象

    2024-03-25 19:38:05       91 阅读

热门阅读

  1. Spark 集群管理器

    2024-03-25 19:38:05       43 阅读
  2. C语言刷题(18)

    2024-03-25 19:38:05       41 阅读
  3. AST抽象语法树&webpack逻辑解析

    2024-03-25 19:38:05       57 阅读
  4. 【C语言】如何将数据写入文件?

    2024-03-25 19:38:05       45 阅读
  5. .NET 依赖注入和配置系统

    2024-03-25 19:38:05       35 阅读
  6. app上传图片和视频

    2024-03-25 19:38:05       32 阅读
  7. Warning: fread(): Length parameter must be greater than 0

    2024-03-25 19:38:05       36 阅读
  8. Docker 容器中运行 JAR 文件的方法

    2024-03-25 19:38:05       45 阅读
  9. 突破编程_C++_查找算法(分块查找)

    2024-03-25 19:38:05       42 阅读
  10. springboot多数据源&动态数据源(主从)

    2024-03-25 19:38:05       37 阅读