Istio金丝雀发布
前言
金丝雀部署的方式有很多种,istio只是其中一种选择, Kubernetes 这样的平台已经提供了进行版本上线和金丝雀部署的方法,但很多问题依然不能解决, 所以使用Istio作为金丝雀部署方案也是很好的选择
金丝雀部署首先部署好新版本,然后让一小部分用户流量引入的新版本进行测试,如果一切顺利,则可以调整比例替换旧版本。如在过程中出现问题,回滚到旧版本即可。最简单的方式,是随机选择百分比请求到金丝雀版本,在更复杂的方案下,可以基于请求的区域,用户或其他属性,本次我们只搞下简单方式。
实验思路和环境
流量从istio-ingressgateway进入,经过创建的gateway,读取VirtualService的流量分配,通过DestinationRule规则关联到pod
实验思路
1、准备两个deployment,设置两个lables,镜像使用nginx即可,为了区分版本,我们进入容器,手动修改一下默认页内容
2、创建svc,选择其中一个labels
3、创建istio gateway
4、创建VirtualService并根据subset分配流量占比
5、创建DestinationRule,设置subsets分别指定不同的lables
6、测试访问
k8s环境
[root@k8s-master istio-canary]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
k8s-master Ready control-plane,master 41d v1.22.0
k8s-node01 Ready <none> 41d v1.22.0
k8s-node02 Ready <none> 41d v1.22.0
istio环境
[root@k8s-master istio-canary]# kubectl get pod,svc -n istio-system
NAME READY STATUS RESTARTS AGE
pod/istio-egressgateway-687f4db598-s6l8v 1/1 Running 0 103m
pod/istio-ingressgateway-78f69bd5db-kcgzb 1/1 Running 0 47m
pod/istiod-76d66d9876-5wnf2 1/1 Running 0 115mNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/istio-egressgateway ClusterIP 10.108.16.157 <none> 80/TCP,443/TCP 3d23h
service/istio-ingressgateway LoadBalancer 10.99.29.225 <pending> 15021:30954/TCP,80:30869/TCP,443:32748/TCP,31400:31230/TCP,15443:30625/TCP 3d23h
service/istiod ClusterIP 10.109.41.38 <none> 15010/TCP,15012/TCP,443/TCP,15014/TCP 3d23h
创建deployment
准备两个deployment,设置两个lables,镜像使用nginx,模拟不同版本的应用
[root@k8s-master istio-canary]# cat deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:name: appv1labels:app: v1
spec:replicas: 1selector:matchLabels:app: v1apply: canarytemplate:metadata:labels:app: v1apply: canaryspec:containers:- name: nginximage: nginxports:- containerPort: 80
---apiVersion: apps/v1
kind: Deployment
metadata:name: appv2labels:app: v2
spec:replicas: 1selector:matchLabels:app: v2apply: canarytemplate:metadata:labels:app: v2apply: canaryspec:containers:- name: nginximage: nginxports:- containerPort: 80
---[root@k8s-master istio-canary]# kubectl apply -f deployment.yaml
deployment.apps/appv1 created
deployment.apps/appv2 created
为了区分两个版本的不通,我们可以修改默认页内容
[root@k8s-master istio-canary]# kubectl get pod
NAME READY STATUS RESTARTS AGE
appv1-5cf75d8d8b-vdvzr 2/2 Running 0 22m
appv2-684dd44db7-r6k6k 2/2 Running 0 22m
[root@k8s-master istio-canary]# kubectl exec appv1-5cf75d8d8b-vdvzr -it /bin/bash
kubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl exec [POD] -- [COMMAND] instead.
root@appv1-5cf75d8d8b-vdvzr:/# echo v1 > /usr/share/nginx/html/index.html
root@appv1-5cf75d8d8b-vdvzr:/# exit
exit
[root@k8s-master istio-canary]# kubectl exec appv2-684dd44db7-r6k6k -it /bin/bash
kubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl exec [POD] -- [COMMAND] instead.
root@appv2-684dd44db7-r6k6k:/# echo v2 > /usr/share/nginx/html/index.html
修改后我们可以创建个svc,然后通过curl svc地址模拟访问一下,访问结果应该是轮询,各百分之50。
[root@k8s-master istio-canary]# cat service.yaml
apiVersion: v1
kind: Service
metadata:name: canarylabels:apply: canary
spec:selector:apply: canaryports:- protocol: TCPport: 80targetPort: 80[root@k8s-master istio-canary]# kubectl apply -f service.yaml
service/canary created
[root@k8s-master istio-canary]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
canary ClusterIP 10.97.182.219 <none> 80/TCP 7s
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 3h11m
[root@k8s-master istio-canary]# curl 10.97.182.219
v2
[root@k8s-master istio-canary]# curl 10.97.182.219
v1
[root@k8s-master istio-canary]# curl 10.97.182.219
v2
[root@k8s-master istio-canary]# curl 10.97.182.219
v1
[root@k8s-master istio-canary]# curl 10.97.182.219
v2
[root@k8s-master istio-canary]# curl 10.97.182.219
v1
[root@k8s-master istio-canary]# curl 10.97.182.219
v2
创建gateway
[root@k8s-master istio-canary]# cat gateway.yaml
apiVersion: networking.istio.io/v1beta1
kind: Gateway
metadata:name: canary-gateway
spec:selector:istio: ingressgatewayservers:- port:number: 80name: httpprotocol: HTTPhosts:- "*"
[root@k8s-master istio-canary]# kubectl apply -f gateway.yaml
gateway.networking.istio.io/canary-gateway created
[root@k8s-master istio-canary]# kubectl get gateways.networking.istio.io
NAME AGE
canary-gateway 7s
创建VirtualService和DestinationRule,其中hosts地址必须加上.cluster.local不然报503错误,查了好久,目前还没找到为啥简写不行,有知道的可以留言指导我一下
[root@k8s-master istio-canary]# cat virtualservice.yaml
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:name: canary
spec:hosts:- "*"gateways:- canary-gatewayhttp:- match:- uri:prefix: /route:- destination:host: canary.default.svc.cluster.localsubset: v1weight: 90- destination:host: canary.default.svc.cluster.localsubset: v2weight: 10
---
apiVersion: networking.istio.io/v1beta1
kind: DestinationRule
metadata:name: canary
spec:host: canary.default.svc.cluster.localsubsets:- name: v1labels:app: v1- name: v2labels:app: v2[root@k8s-master istio-canary]# kubectl apply -f virtualservice.yaml
virtualservice.networking.istio.io/canary created
destinationrule.networking.istio.io/canary created
到目前为止环境已经就绪,可以开始测试,因为流量是从istio-ingressgateway进入,所以需要先查看一下svc的入口,入口为LoadBlancer模式,此模式一般用于云厂商的负载均衡,我们也可以使用节点方式访问,80端口已经映射出了对应的端口30869
[root@k8s-master istio-canary]# kubectl get svc -n istio-system
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
istio-egressgateway ClusterIP 10.108.16.157 <none> 80/TCP,443/TCP 4d1h
istio-ingressgateway LoadBalancer 10.99.29.225 <pending> 15021:30954/TCP,80:30869/TCP,443:32748/TCP,31400:31230/TCP,15443:30625/TCP 4d1h
istiod ClusterIP 10.109.41.38 <none> 15010/TCP,15012/TCP,443/TCP,15014/TCP 4d1h
[root@k8s-master istio-canary]# curl 192.168.3.50:30869
v1
[root@k8s-master istio-canary]# curl 192.168.3.50:30869
v1
[root@k8s-master istio-canary]# curl 192.168.3.50:30869
v1
[root@k8s-master istio-canary]# curl 192.168.3.50:30869
v1
[root@k8s-master istio-canary]# curl 192.168.3.50:30869
v1
通过手动curl测试效果并不好,因为访问的次数少,所以我们可以通过循环来访问
[root@k8s-master istio-canary]# for ((i=1;i<=100;i++)); do curl 192.168.3.50:30869; done
结果太长不贴了,统计结果如下,大约是90:10
[root@k8s-master istio-canary]# cat /tmp/curl.txt |sort |uniq -c89 v111 v2
修改流量
[root@k8s-master istio-canary]# kubectl edit virtualservices.networking.istio.io canary...route:- destination:host: canary.default.svc.cluster.localsubset: v1weight: 70 # 由90修改为70- destination:host: canary.default.svc.cluster.localsubset: v2weight: 30 # 由10修改为30
...
修改完之后再次执执行循环curl命令,统计结果信息如下
[root@k8s-master istio-canary]# for ((i=1;i<=100;i++)); do curl 192.168.3.50:30869; done > /tmp/curl.txt[root@k8s-master istio-canary]# cat /tmp/curl.txt |sort |uniq -c70 v130 v2
目前只完成了这些,接下来会尝试控制固定区域访问,实现内部测试,并研究一下发布流程,欢迎朋友们留言指导,一起交流学习
Istio金丝雀发布相关推荐
- 一文搞懂蓝绿部署和金丝雀发布
在之前关于CI/CD的文章中,我们简单讨论了蓝绿部署和金丝雀发布以及它们在持续交付中所扮演的角色.这些都是十分有效的方法,能够大大降低与应用程序部署相关的风险.所以,这篇文章我们来深入介绍蓝绿部署和金 ...
- 1W字长文:蓝绿发布、金丝雀发布、滚动发布、A/B测试 原理和实操
背景: 蓝绿发布.金丝雀发布.滚动发布.A/B测试 ,是大家日常常见的发布工作.所以发布的原理和实操是一个非常.非常核心的面试知识点. 在40岁老架构师 尼恩的读者交流群(50+)中,其相关面试题是一 ...
- 微服务部署:蓝绿发布、滚动发布、灰度发布、金丝雀发布
在项目迭代的过程中,不可避免需要上线.上线对应着部署,或者重新部署:部署对应着修改,修改则意味着风险. 1.蓝绿发布(Blue/Green Deployment) ①定义 蓝绿部署是不停老版本,部署新 ...
- 【云原生 | 从零开始学istio】五、istio灰度发布以及核心资源
istio灰度发布 接着上一章部署bookinfo 通过 Istio 实现灰度发布 什么是灰度发布? 使用 istio 进行灰度发布 istio 核心资源解读 Gateway VirtualServi ...
- 蓝绿部署、金丝雀发布(灰度发布)、AB测试……
点击关注公众号,Java干货及时送达 来源 | https://www.jianshu.com/p/0df88fe4a1e3 随着微服务架构的普及,线上服务越来越多,随之而来的就是部署越来越频繁:随着 ...
- 微服务治理实践 | 金丝雀发布
来自:阿里巴巴中间件 前言 阿里巴巴集团内部有不少故障是因为发布直接或间接引起.因此提升发布的质量,减少错误的发生,是有效减少线上故障的一个关键环节. 为什么大部分的故障和发布相关?因为发布是整个功能 ...
- 使用级联功能实现蓝绿部署和金丝雀发布
点击蓝色"程序猿DD"关注我 回复"资源"获取独家整理的学习资料! 作者:米开朗基杨 来源:公众号「云原生实验室」 上篇文章介绍了 Contour 分布式架构的 ...
- 微服务部署:蓝绿部署、滚动部署、灰度发布、金丝雀发布
在项目迭代的过程中,不可避免需要"上线".上线对应着部署,或者重新部署:部署对应着修改:修改则意味着风险. 目前有很多用于部署的技术,有的简单,有的复杂:有的得停机,有的不需要停机 ...
- 蓝绿部署滚动部署金丝雀发布(灰度发布)A/B测试
在一般情况下,升级服务器端应用,需要将应用源码或程序包上传到服务器,然后停止掉老版本服务,再启动新版本.但是这种简单的发布方式存在两个问题,一方面,在新版本升级过程中,服务是暂时中断的,另一方面,如果 ...
最新文章
- XXX管理平台系统——会议管理
- c语言程序设计运算符及表达式,c语言程序设计3第3章运算符和表达式
- 数据中心可以从云计算学习可持续性运营
- 一天1个机器学习知识点(四)
- linux子系统 重置,浅析win10系统重置Linux子系统的设置方法
- java json注解_返回json用什么注解
- nvm安装npm出错问题解决方案
- revit二次开发概念_BIM百科 | Revit二次开发入门--创建一个简单的程序
- Oracle 常见错误代码处理 1
- visio2019即点即用版本兼容下载与安装
- 计算机无法识别psp usb设备,PSP降级导致USB连接电脑识别问题解决办法
- 于佳宁担任BCF理事
- 13.大容量存储结构(磁盘管理)
- 数字逻辑电路设计(实验测试题)
- GDScript:关于派生类调用基类方法的一个注意事项
- PHP汉字转拼音函数
- 角雷达进入“高速增长期”,国产供应商迎来“突围”时间窗口
- 【JAVA】500勇士问题,杀掉第三个人
- 2019年全国职业院校技能大赛—大数据技术与应用
- 小学计算机课标教学大纲的依据,《中小学课程标准与教学大纲有什么区别和联系》...