Istio Routing极简教程
官网文档:
https://istio.io/docs/reference/config/networking/#VirtualService
在学习像Istio这样的新技术时,看一下示例应用程序总是一个好主意。 Istio repo有一些示例应用程序,但它们似乎有各种不足。 文档中的BookInfo是一个很好的示例。 但是,对于我而言,它太冗长,服务太多,而且文档似乎专注于管理BookInfo应用程序,而不是从头开始构建。 有一个较小的helloworld例子,但它更多的是关于自动伸缩而不是其他。 在这篇文章中,我想介绍一下基础知识,并展示如何从头开始构建支持Istio的“HelloWorld”应用程序。 要记住的一点是,Istio只管理你应用的流量。 在这种情况下,应用程序生命周期由底层平台Kubernetes管理。 因此,你需要了解容器和Kubernetes基础知识,并且需要了解Istio Routing原语,例如Gateway,VirtualService,DestinationRule。 我假设大多数人都知道容器和Kubernetes基础知识。 我将在本文中专注于Istio Routing。 # 基础步骤 以下这些大致就是你需要遵循的,以获得Istio的“HelloWorld”应用程序的步骤:
创建一个Kubernetes集群并安装带有sidecare自动注入的Istio。
使用你选择的语言创建Hello World应用程序,创建Docker镜像并将其推送到公共镜像仓库。
为你的容器创建Kubernetes Deployment和Service。
创建Gateway以启用到群集的HTTP(S)流量。
创建VirtualService,通过Gateway公开Kubernetes服务。
(可选)如果要创建多个版本应用程序,请创建DestinationRule以定义可从VirtualService引用的subsets。
(可选)如果要在服务网格外部调用其他外部服务,请创建ServiceEntry。
我不会在本文中介绍步骤1和2,因为它们不是特定于Istio的。 如果您需要有关这些步骤的帮助,可以查看我在本文末尾提到的文章。 第3步也不是Istio特定的,但它是其他一切的先决条件,所以让我们从那开始。 # Deployment和Service 正如我所提到的,应用程序生命周期由Kubernetes管理。 因此,您需要从创建Kubernetes Deployment和Service开始。 我的情况如下,我有一个容器化的ASP.NET核心应用程序,其镜像我已经推送到谷歌镜像仓库。 让我们从创建一个aspnetcore.yaml
文件开始:
apiVersion: v1
kind: Service
metadata:
name: aspnetcore-service
labels:
app: aspnetcore
spec:
ports:
- port: 8080
name: http
selector:
app: aspnetcore
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: aspnetcore-v1
spec:
replicas: 1
template:
metadata:
labels:
app: aspnetcore
version: v1
spec:
containers:- name: aspnetcore
image: gcr.io/istio-project-212517/hello-dotnet:v1
imagePullPolicy: Always #IfNotPresent
ports:- containerPort: 8080
创建Deployment和Service:
$ kubectl apply -f aspnetcore.yaml
service "aspnetcore-service" created
deployment.extensions "aspnetcore-v1" created
到目前为止没有任何特定的针对Istio的内容。 # Gateway 我们现在可以开始研究Istio Routing。 首先,我们需要为服务网格启用HTTP/HTTPS流量。 为此,我们需要创建一个网关。 Gateway描述了在边缘运行的负载均衡,用于接收传入或传出的HTTP/TCP连接。 让我们创建一个aspnetcore-gateway.yaml
文件:
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: aspnetcore-gateway
spec:
selector:
istio: ingressgateway # use istio default controller
servers:
- containerPort: 8080
- name: aspnetcore
- port:
number: 80
name: http
protocol: HTTP
hosts:- "*"
创建Gateway:
$ kubectl apply -f aspnetcore-gateway.yaml
gateway.networking.istio.io "aspnetcore-gateway" created
此时,我们为集群启用了HTTP流量。 我们需要将之前创建的Kubernetes服务映射到Gateway。 我们将使用VirtualService执行此操作。 # VirtualService VirtualService实际上将Kubernetes服务连接到Istio网关。 它还可以执行更多操作,例如定义一组流量路由规则,以便在主机被寻址时应用,但我们不会深入了解这些细节。 让我们创建一个aspnetcore-virtualservice.yaml
文件:
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: aspnetcore-virtualservice
spec:
hosts:
- "*"
- "*"
gateways: - aspnetcore-gateway
http: - route:
destination:
host: aspnetcore-service
请注意,VirtualService与特定网关绑定,并定义引用Kubernetes服务的主机。 创建VirtualService:
$ kubectl apply -f aspnetcore-virtualservice.yaml
virtualservice.networking.istio.io "aspnetcore-virtualservice" created测试V1版本APP 我们准备测试我们的应用程序了。 我们需要获取Istio Ingress Gateway的IP地址:
$ kubectl get svc istio-ingressgateway -n istio-system
NAME TYPE CLUSTER-IP EXTERNAL-IP
istio-ingressgateway LoadBalancer 10.31.247.41 35.240.XX.XXX
当我们在浏览器中打开EXTERNAL-IP
时,我们应该看到HelloWorld ASP.NET Core应用程序:
1.pngDestinationRule 在某些时候,你希望将应用更新为新版本。 也许你想分割两个版本之间的流量。你需要创建一个DestinationRule来定义是哪些版本,在Istio中称为subset。 首先,更新aspnetcore.yaml文件以使用v2版本的容器定义v2的deployment:
apiVersion: v1
kind: Service
metadata:
name: aspnetcore-service
labels:
app: aspnetcore
spec:
ports:
- port: 8080
name: http
selector:
app: aspnetcore
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: aspnetcore-v1
spec:
replicas: 1
template:
metadata:
labels:
app: aspnetcore
version: v1
spec:
containers:- name: aspnetcore
image: gcr.io/istio-project-212517/hello-dotnet:v1
imagePullPolicy: Always #IfNotPresent
ports:- containerPort: 8080
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: aspnetcore-v2
spec:
replicas: 1
template:
metadata:
labels:
app: aspnetcore
version: v2
spec:
containers:
- containerPort: 8080
- name: aspnetcore
image: gcr.io/istio-project-212517/hello-dotnet:v2
imagePullPolicy: Always #IfNotPresent
ports:- containerPort: 8080
创建新的Deployment:
$ kubectl apply -f aspnetcore.yaml
service "aspnetcore-service" unchanged
deployment.extensions "aspnetcore-v1" unchanged
deployment.extensions "aspnetcore-v2" created
如果使用EXTERNAL-IP刷新浏览器,您将看到应用程序的v1和v2版本交替出现:
2.png
3.png
这是符合预期的,因为两个版本都暴露在相同的Kubernetes服务之后:aspnetcore-service。 如果您想将服务仅指向v2,该怎么办? 这可以通过在VirtualService中指定subset来完成,但我们需要首先在DestinationRules中定义这些subset。 DestinationRule本质上是将标签映射到Istio的subset。 创建一个aspnetcore-destinationrule.yaml
文件:
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
name: aspnetcore-destinationrule
spec:
host: aspnetcore-service
trafficPolicy:
tls:
mode: ISTIO_MUTUAL
subsets:
- containerPort: 8080
- name: aspnetcore
- name: v1
labels:
version: v1 - name: v2
labels:
version: v2
创建DestinationRule:
$ kubectl apply -f aspnetcore-destinationrule.yaml
destinationrule.networking.istio.io "aspnetcore-destinationrule" created
现在你可以从VirtualService来引用v2 subset:
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: aspnetcore-virtualservice
spec:
hosts: - "*"
gateways: - aspnetcore-gateway
http: - route:
- destination:
host: aspnetcore-service
subset: v2
更新VirtualService:
$ kubectl apply -f aspnetcore-virtualservice.yaml
virtualservice.networking.istio.io "aspnetcore-virtualservice" configured
如果你现在继续浏览EXTERNAL-IP,您现在应该只能看到应用程序的v2版本。 # ServiceEntry 我想在Istio Routing中提到的最后一件事是ServiceEntry。默认情况下,Istio中的所有外部流量都被阻止。如果要启用外部流量,则需要创建ServiceEntry以列出为外部流量启用的协议和主机。我不会在这篇文章中展示一个例子,但你可以在这里阅读更多相关内容。 希望这篇文章对你有用!如果您想了解更多信息,可以使用codelab系列以下两部分,其中所有这些概念和更多内容将在逐步的详细教程中进行说明:
Deploy ASP.NET Core app to Google Kubernetes Engine with Istio (Part 1)
Deploy ASP.NET Core app to Google Kubernetes Engine with Istio (Part 2)
原文链接:Istio Routing Basics(翻译:kelvinji2009)
- destination:
Istio Routing极简教程的更多相关文章
- Typora极简教程
Typora极简教程 ” Markdown 是一种轻量级标记语言,创始人是约翰·格鲁伯(John Gruber).它允许人们 “使用易读易写的纯文本格式编写文档,然后转换成有效的 HTML 文档.” ...
- CentOS安装使用.netcore极简教程(免费提供学习服务器)
本文目标是指引从未使用过Linux的.Neter,如何在CentOS7上安装.Net Core环境,以及部署.Net Core应用. 仅针对CentOS,其它Linux系统类似,命令环节稍加调整: 需 ...
- Asky极简教程:零基础1小时学编程,已更新前8节
Asky极简架构 开源Asky极简架构.超轻量级.高并发.水平扩展.微服务架构 <Asky极简教程:零基础1小时学编程>开源教程 零基础入门,从零开始全程演示,如何开发一个大型互联网系统, ...
- Python 极简教程(八)字符串 str
由于字符串过于重要,请认真看完并保证所有代码都至少敲过一遍. 对于字符串,前面在数据类型中已经提到过.但是由于字符串类型太过于常用,Python 中提供了非常多的关于字符串的操作.而我们在实际编码过程 ...
- Nginx 极简教程(快速入门)
作者:dunwu github.com/dunwu/nginx-tutorial 推荐阅读(点击即可跳转阅读) 1. SpringBoot内容聚合 2. 面试题内容聚合 3. 设计模式内容聚合 4. ...
- 【转】Typora极简教程
Typora极简教程 Typora download ” Markdown 是一种轻量级标记语言,创始人是约翰·格鲁伯(John Gruber).它允许人们 “使用易读易写的纯文本格式编写文档,然后转 ...
- nginx极简教程
Nginx 极简教程 本项目是一个 Nginx 极简教程,目的在于帮助新手快速入门 Nginx. examples 目录中的示例模拟了工作中的一些常用实战场景,并且都可以通过脚本一键式启动,让您可以快 ...
- NodeJS 极简教程 <1> NodeJS 特点 & 使用场景
NodeJS 极简教程 <1> NodeJS 特点 & 使用场景 田浩 因为看开了所以才去较劲儿. 1. NodeJS是什么 1.1 Node.js is a JavaScri ...
- 自制 os 极简教程1:写一个操作系统有多难
为什么叫极简教程呢?听我慢慢说 不知道正在阅读本文的你,是否是因为想自己动手写一个操作系统.我觉得可能每个程序员都有个操作系统梦,或许是想亲自动手写出来一个,或许是想彻底吃透操作系统的知识.不论是为了 ...
随机推荐
- ubuntu18.04 中个性化配置vim方法
1:新建配置文件 在终端里输入:vi ~/.vimrc (vimrc是vim的配置文件,每次打开vim时会自动加载这个文件里的配置) 2:配置的代码如下:直接就可以复制到里面然后保存就行 set ai ...
- vsc 自定义快速生成vue模板
1.安装vscode 官网地址:https://code.visualstudio.com/ 2.安装一个插件,识别vue文件 插件库中搜索Vetur,下图中的第一个,点击安装,安装完成之后点击重新加 ...
- PELT算法
参考:http://www.wowotech.net/process_management/PELT.html 本文是对https://lwn.net/Articles/531853/的翻译 mark ...
- Caused by: org.springframework.data.mapping.PropertyReferenceException: No property id found for type Users!
Spring Data JPA自定义Repository Caused by: org.springframework.data.mapping.PropertyReferenceException: ...
- java.lang.ClassNotFoundException: XXX (no security manager: RMI class loader disabled)
在搞RMI远程发布,consumer去获取rmi远程服务的代理对象的时候出现了如下的错误 问题发现: 由于我发布的对象的包路径和获取的对象的包路径不一致,导致了这样的问题 解决方案: 包路径改为一致就 ...
- wpf file embeded resource is readonly,Copy always will copy the file and its folder to the bin folder
Wpf file embeded resource will compile the file into the assembly and it will be readonly and can no ...
- 软件设计之基于Java的连连看小游戏(二)——游戏基础界面的制作及事件的添加
上次完成到游戏首页的制作,今天完成了游戏基础界面的制作以及事件的简单添加.由于功能尚未完全实现,因此游戏界面的菜单列表只是简单地添加了一下,其余菜单列表以及倒计时等在后续的制作中逐一完善. 1.首先在 ...
- Winform中在ZedGraph中最多可以添加多少条曲线
场景 Winforn中设置ZedGraph曲线图的属性.坐标轴属性.刻度属性: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/10 ...
- 证券secuerity英语secuerity安全
中文名:证券 外文名:security.secuerity 类别:经济权益凭证统称 组成:资本证券.货币证券和商品证券 作用:用来证明持者权益的法律凭证 图集 目录 1 发展历程 ? 世界 ? 中国 ...
- [转]C#操作Outlook
本文转自:https://blog.csdn.net/yanlovehan/article/details/8500449 //引用Microsoft.Office.Interop.Outlook.d ...