当前位置: 首页 > news >正文

K8S + ISTIO 金丝雀部署的例子

金丝雀发布(Canary):也是一种发布策略,和国内常说的灰度发布是同一类策略。蓝绿部署是准备两套系统,在两套系统之间进行切换,金丝雀策略是只有一套系统,逐渐替换这套系统。
Istio 提供一种简单的方式来为已部署的服务建立网络,该网络具有负载均衡、服务间认证、监控等功能,只需要对服务的代码进行一点或不需要做任何改动。想要让服务支持 Istio,只需要在您的环境中部署一个特殊的 sidecar 代理,使用 Istio 控制平面功能配置和管理代理,拦截微服务之间的所有网络通信:

HTTP、gRPC、WebSocket 和 TCP 流量的自动负载均衡。
通过丰富的路由规则、重试、故障转移和故障注入,可以对流量行为进行细粒度控制。
可插入的策略层和配置 API,支持访问控制、速率限制和配额。
对出入集群入口和出口中所有流量的自动度量指标、日志记录和追踪。
通过强大的基于身份的验证和授权,在集群中实现安全的服务间通信。
Istio 旨在实现可扩展性,满足各种部署需求。

ISTIO 金丝雀部署
1.定义k8s的service demo4

apiVersion: v1
kind: Service
metadata:name: demo4namespace: test1labels:app: demo4
spec:ports:- port: 80targetPort: httpprotocol: TCPname: httpselector:app: demo4

2. 定义两个版本的 deploy 文件
两个版本都包含服务选择标签 app:demo4

apiVersion: apps/v1beta1
kind: Deployment
metadata:name: demo4-deployment-v1namespace: test1
spec:replicas: 1template:metadata:annotations:# 允许注入 sidecarsidecar.istio.io/inject: "true"labels:app: demo4version: v1spec:containers:- name: demo4-v1image: mritd/demolivenessProbe:httpGet:path: /port: 80scheme: HTTPinitialDelaySeconds: 30timeoutSeconds: 5periodSeconds: 10successThreshold: 1failureThreshold: 5readinessProbe:httpGet:path: /port: 80scheme: HTTPinitialDelaySeconds: 30timeoutSeconds: 5periodSeconds: 10successThreshold: 1failureThreshold: 5ports:- name: httpcontainerPort: 80protocol: TCP---
apiVersion: apps/v1beta1
kind: Deployment
metadata:name: demo4-deployment-v2namespace: test1
spec:replicas: 1template:metadata:labels:app: demo4version: v2annotations:sidecar.istio.io/inject: "true"spec:containers:- name: demo4-v2image: mritd/demolivenessProbe:httpGet:path: /port: 80scheme: HTTPinitialDelaySeconds: 30timeoutSeconds: 5periodSeconds: 10successThreshold: 1failureThreshold: 5readinessProbe:httpGet:path: /port: 80scheme: HTTPinitialDelaySeconds: 30timeoutSeconds: 5periodSeconds: 10successThreshold: 1failureThreshold: 5ports:- name: httpcontainerPort: 80protocol: TCP

上面定义和普通k8s定义蓝绿部署是一样的

3. 设置路由规则来控制流量分配
如将 10% 的流量发送到金丝雀版本(v2), 后面可以渐渐的把所有流量都切到金丝雀版本(v2),只需要修改weight: 10参数,注意v1和v2版本和一定要等于100.

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:name: demo4-vsnamespace: test1
spec:hosts:- demo4.a.comgateways:- demo4-gatewayhttp:- route:- destination:host: demo4.test1.svc.cluster.localsubset: v1weight: 90- destination:host: demo4.test1.svc.cluster.localsubset: v2weight: 10
---
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:name: demo4namespace: test1
spec:host: demo4.test1.svc.cluster.localsubsets:- name: v1labels:version: v1- name: v2labels:version: v2

高层次的金丝雀部署
只允许特定网站上50%的用户流量路由到金丝雀(v2)版本,而其他用户则不受影响.

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:name: demo4-vsnamespace: test1
spec:hosts:- demo4.a.comgateways:- demo4-gatewayhttp:- match:- headers:cookie:regex: "^(.*?;)?(email=[^;]*@some-company-name.com)(;.*)?$"route:- destination:host: demo4.test1.svc.cluster.localsubset: v1weight: 50- destination:host: demo4.test1.svc.cluster.localsubset: v2weight: 50- route:- destination:host: demo4.test1.svc.cluster.localsubset: v1

说明:
Istio Virtual Service,用于控制当前deployment和金丝雀deployment流量分配的权重
Istio Destination Rule,包含当前deployment和金丝雀deployment的子集(subset)
Istio Gateway(可选),如果服务需要从容器集群外被访问则需要搭建gateway
Istio 服务网格提供了管理流量分配所需的基础控制,并完全独立于部署缩放。这允许简单而强大的方式来进行金丝雀测试和上线。

http://www.lryc.cn/news/33490.html

相关文章:

  • python自带数据的模型合集
  • 女生学习大数据怎么样~有前景么
  • 统计代码量
  • uniapp在线升级关联云空间
  • 学习streamlit-2
  • Vscode中Vue文件保存格式化、 ElementUI、Font Awesome俩大插件使用
  • 汽车标定知识整理(三):CCP报文可选命令介绍
  • kubeadm安装K8S(集群)
  • Baumer工业相机堡盟相机如何使用PnPEventHandler实现相机掉线自动重连(C++新)
  • Windows 命令行基础
  • 面试官: 谈下音视频同步原理,音频和视频能绝对同步吗?
  • CFS三层靶机安装与配置
  • 爬虫入门教程-Spider
  • Python|蓝桥杯进阶第二卷——贪心
  • Chrome开发使用技巧总结
  • 你真的会在阳光下拍照片么?
  • 量化择时——均线策略及改进方法(第1部分—因子测算)
  • 封装几个有用的 Vue3 组合式API
  • MyBatisPlus中的条件构造器Wrapper
  • 类和对象及其构造方法
  • HStream Console、HStreamDB 0.14 发布
  • 参考文献怎么查找,去哪里查找?一篇文章讲明白这些问题
  • docker-compose+HAProxy+Keepalived搭建高可用 RabbitMQ 集群
  • 自动化框架如何搭建?让10年阿里自动化测试老司机帮你搞定!自动化测试脚本怎么写?
  • 剑指 Offer 15. 二进制中1的个数
  • CHAPTER 3 磁盘管理
  • MS python学习(7)
  • 工业物联网“杀手级”应用—预测性维护
  • Java代码弱点与修复之——Explicit null dereferenced(显式空间接引用)
  • 一元导数与多元求导数总结