首页 > 其他分享 >备考ICA----Istio实验4---使用 Istio 进行金丝雀部署

备考ICA----Istio实验4---使用 Istio 进行金丝雀部署

时间:2024-03-22 13:59:09浏览次数:36  
标签:name 金丝雀 Istio helloworld istio --- v1 v2 canary

备考ICA----Istio实验4—使用 Istio 进行金丝雀部署

上一个实验已经通过DestinationRule实现了部分金丝雀部署的功能,这个实验会更完整的模拟展示一个环境由v1慢慢过渡到v2版本的金丝雀发布.

1. 环境清理

kubectl delete gw/helloworld-gateway vs/helloworld dr/helloworld-destination

测试

kubectl get svc,pods
for i in {1..10};do curl $(kubectl get svc helloworld|grep helloworld|awk '{print $3":"$5}'|awk -F"/" '{print $1"/hello"}');sleep .5 ;done
kubectl get gw,vs,dr

在这里插入图片描述
恢复到这样就可以通过helloworld的svc将流量随机分配到v1和v2上
如果实验环境有问题,就重新部署hello

kubectl delete -f istio/samples/helloworld/helloworld.yaml
kubectl apple -f istio/samples/helloworld/helloworld.yaml

2. 所有流量转发到v1

这步就模拟只存在1个版本的环境
canary/helloworld-canary-all-v1.yaml

apiVersion: networking.istio.io/v1beta1
kind: Gateway
metadata:
  name: helloworld-gateway
spec:
  selector:
    istio: ingressgateway # use istio default controller
  servers:
  - port:
      number: 80
      name: http
      protocol: HTTP
    hosts:
    - "*"
---
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
      weight: 100

部署gw,vs,dr

kubectl apply -f canary/helloworld-canary-all-v1.yaml

测试效果
此时所有流量都交由v1进行响应

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

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

3. 90%流量v1,10%流量v2

此时v2版本应用已经上线,将10%流量给v2,其余流量仍由v1进行应答

3.1 配置流量分发比例

canary/helloworld-canary-allin1-10v2.yaml

apiVersion: networking.istio.io/v1beta1
kind: Gateway
metadata:
  name: helloworld-gateway
spec:
  selector:
    istio: ingressgateway # use istio default controller
  servers:
  - port:
      number: 80
      name: http
      protocol: HTTP
    hosts:
    - "*"
---
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
      weight: 90
    - destination:
        host: helloworld
        port:
          number: 5000
        subset: v2
      weight: 10

部署gw,vs,dr

kubectl apply -f canary/helloworld-canary-allin1-10v2.yaml 

测试效果
可以看到10个请求中有1个由v2应答,其他仍由v1进行响应
在这里插入图片描述
在这里插入图片描述

3.2 加入Hpa

---
apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
  name: hpa-helloworld-v1
spec:
  maxReplicas: 20
  minReplicas: 1
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: helloworld-v1
  targetCPUUtilizationPercentage: 50
---
apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
  name: hpa-helloworld-v2
spec:
  maxReplicas: 20
  minReplicas: 1
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: helloworld-v2
  targetCPUUtilizationPercentage: 50

部署hpa

kubectl apply -f canary/hpa.yaml

3.3 压测

 while true;do curl http://192.168.126.220/hello;done

产生大量请求
在这里插入图片描述

此时v1,v2因访问量大触发hpa扩容,直到v1到达上线16个pod,v2到达3个

在这里插入图片描述

4. 50%流量v1,50%流量v2

4.1 配置流量分发比例

dr和gw部分就不用动了.只要修改vs的weight部分就可以
canary/helloworld-canary-vs-50v2.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: 50
    - destination:
        host: helloworld
        port:
          number: 5000
        subset: v2
      weight: 50

部署

kubectl apply -f canary/helloworld-canary-vs-50v2.yaml

4.2 压测

此时流量以1:1分发给v1和v2
在这里插入图片描述

再观测hpa的情况会发现v2的cpu逐渐升高,v1的cpu逐渐降低,v2开始扩容,v1开始缩容,逐渐扩缩容到10:10
在这里插入图片描述
在这里插入图片描述

5. 所有流量转发v2

51. 配置流量分发比例

中间的10%,90%其实和前2个版本差不多,直接修改下数值就可以了.我们这里就忽略了,有兴趣的老哥可以进一步的修改模拟.
这里就模拟经过测试v2版本已经没有问题,我们将所有流量打到v2上
canary/helloworld-canary-all-v2.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: v2
      weight: 100

部署

kubectl apply -f canary/helloworld-canary-all-v2.yaml

5.2 压测

while true;do curl http://192.168.126.220/hello;done

在这里插入图片描述
在这里插入图片描述
至此canary的一个模拟从v1到v2的版本切换就已经完成了

6. 拓展Canary+AB测试

6.1 canary+ab配置

当我们进行canary测试的时候,普通用户是以50%:50%的流量分发到2个版本上,但我们希望测试人员trump同学,每次都是访问到新上线的v2版本上.
canary/canary-ab-vs.yaml

apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: helloworld
spec:
  hosts:
  - "*"
  gateways:
  - helloworld-gateway
  http:
  - match:
    - headers:
        user:
          exact: trump
      uri:
        exact: /hello
    route:
    - destination:
        host: helloworld
        port:
          number: 5000
        subset: v2
      weight: 100
  - route:
    - destination:
        host: helloworld
        port:
          number: 5000
        subset: v1
      weight: 50
    - destination:
        host: helloworld
        port:
          number: 5000
        subset: v2
      weight: 50

部署应用

kubectl apply -f canary/canary-ab-vs.yaml

在这里插入图片描述

6.2 测试

6.2.1 普通用户测试

这部分用户进准的按1:1流量访问v1和v2

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

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

6.2.2 测试人员访问

当测试人员trump访问时,匹配header中的用户名为trump,流量就被100%的打到v2版本上

for i in {1..20};do curl -H "user:trump" http://192.168.126.220/hello;done

在这里插入图片描述
在这里插入图片描述
至此整个金丝雀部署完成

标签:name,金丝雀,Istio,helloworld,istio,---,v1,v2,canary
From: https://blog.csdn.net/qq_29974229/article/details/136932353

相关文章

  • Deepin-安装Docker
    1deepin版本社区版20.7.12安装依赖包sudoapt-getupdatesudoapt-getinstall\apt-transport-https\ca-certificates\curl\gnupg-agent\software-properties-common-ycurl-fsSLhttps://download.docker.com/linux/ubuntu/gpg|sudo......
  • 基于51单片机智能停车场管理车位引导系统红外检测OLED设计21-295
    21-295、51单片机智能停车场管理车位引导系统红外检测OLED液晶汉字显示设计产品功能描述:本系统由STC89C52单片机、红外对管传感器、0.96寸OLED液晶屏、LED指示灯及电源组成。1、通过红外对管模块实时检测车位是否占用,车位分为1车位,2车位,3车位。2、液晶实时显示车位是否被占......
  • 基于STM32单片机图书馆智能节能灯热释人体感应光照设计21-304
    21-304、STM32图书馆智能节能灯设计-LCD1602-热释-光敏-拨动-KEY-RELAY产品功能描述:本设计由STM32F103C8T6单片机核心板电路+拨动开关电路+按键电路+2路继电器控制电路+热释人体红外模块电路+光照检测电路+LCD1602液晶显示电路+电源电路组成1、通过拨动开关选择系统工作模式......
  • 完全理解ARM启动流程:Uboot-Kernel
    内容共计5W+字数,但是我还是很多地方说的不够尽兴。那么下次聊!前言bootloader是系统上电后最初加载运行的代码。它提供了处理器上电复位后最开始需要执行的初始化代码。PC机上引导程序一般由BIOS开始执行,然后读取硬盘中位于MBR(MainBootRecord,主引导记录)中的Bootload......
  • Linux-Java安装了多个版本
    近日在Deepin上发现安装了多个版本,但是我们仅仅指定的版本,这时就需要手工切换,切换方法如下:如果你发现有两个不同版本的OpenJDK,可能是因为系统默认安装了一个版本,而你可能也安装了另一个版本。要确定哪个版本正在被使用,你可以在终端中运行以下命令:java-version这将显示当前......
  • LLM-通义千问:新能源参考书
    问题一:新能源入门参考书对于新能源技术的学习,以下是一些推荐的入门参考书籍:《新能源概论》:作者孙逢春,该书全面介绍了太阳能、风能、生物质能、海洋能等各种新能源的基本原理、利用技术及其发展趋势,适合初学者了解新能源领域的全貌。《新能源科学与工程导论》:作者张华,该书......
  • C语言-教案04(从小白到劝退之运算符)
    算术运算符运算符功能说明举例+加法,一目取正a+b-减法,一目取负a-b*乘法a*b/除法a/b%取模(求余)a%b++自加1a++,++b--自减1a--,--b关注点:减号也是负号,比如-a是取变量a的相反数。取模运算要求左右两边操作数必须是整型数据......
  • 深度学习模型的基础--感知机
    AI大模型学习在当前技术环境下,AI大模型学习不仅要求研究者具备深厚的数学基础和编程能力,还需要对特定领域的业务场景有深入的了解。通过不断优化模型结构和算法,AI大模型学习能够不断提升模型的准确性和效率,为人类生活和工作带来更多便利。方向一:AI大模型学习的理论基础提示......
  • 【前端面试题-07】typescript 内置类型有哪些,分别简单介绍下用法
    TypeScript提供了一系列内置类型,这些类型有助于编写类型安全的代码。以下是TypeScript中一些重要的内置类型及其用途的简介:基本类型:boolean:表示布尔值,只有两种可能的值true或false。number:表示任何数值,包括整数和浮点数。string:表示文本字符串。bigint(ES2020):表示......
  • SpringBoot - [03] SpringBoot整合Mybatis Plus连接数据库
    原文链接:https://mp.weixin.qq.com/s/ZJTKX_gmn6ffsY7hNrspHQ 一、开发环境JDK:1.8SpringBoot:2.1.1.RELEASEMySQL:8.0.28 二、引入依赖<dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-boot-starter</artifactId&g......