Istio-Egress发起HTTP请求
创建sleep客户端apiVersion: v1kind: ServiceAccountmetadata: name: sleep---apiVersion: v1kind: Servicemetadata: name: sleep labels: app: sleepspec: ports: - port: 80 name: http selector: app: sleep---apiVersion: apps/v1kind: Deploymentmetadata: name: sleepspec: selector: matchLabels: app: sleep template: metadata: labels: app: sleep spec: serviceAccountName: sleep containers: - name: sleep image: pstauffer/curl ...
Istio-ServiceEntry
添加服务条目(ServiceEntry)后,Envoy代理可以将流量发送到该服务,简单的理解,就是将外部的服务加入到网格一样,从而实现针对外部服务,也可以利用一些Istio流量策略。
ServiceEntry样例部署sleep资源
apiVersion: v1kind: ServiceAccountmetadata: name: sleep---apiVersion: v1kind: Servicemetadata: name: sleep labels: app: sleepspec: ports: - port: 80 name: http selector: app: sleep---apiVersion: apps/v1kind: Deploymentmetadata: name: sleepspec: selector: matchLabels: app: sleep template: metadata: labels: app: sleep spec: se ...
Istio-ingressgateway配置HTTPS
通过配置443端口的ingress网关以处理HTTPS流量
生成证书mkdir -p /etc/istio/ingressgateway-certscd /etc/istio/ingressgateway-certsopenssl genrsa -out "ca.key" 2048# Common Name 填写域名openssl req -new -key "ca.key" -out "ca.csr"openssl x509 -req -days 365 -in "ca.csr" -signkey "/ca.key" -out "ca.crt"
生成secret
该 secret 必须在 istio-system 命名空间下,且名为 istio-ingressgateway-certs
kubectl create -n istio-system secret tls istio-ingres ...
Istio-ingressgateway
Kubernetes Ingress资源在具有简单的HTTP流量的各种场景下相对易于使用,但是在复杂的场景中存在其缺点,主要是因为其围绕路由规则的功能非常有限。使用Istio进行入口时,最明显的优势是获得了与Istio提供的路由流量相同级别的配置选项。通过自定义资源以及TLS终止、监视、跟踪和其他一些功能,可以轻松地重写各种匹配规则、重定向路由等。
在Kubernetes Ingress中,入口控制器负责监视入口资源并配置入口代理。在Istio中,控制器(istiod)是控制层面的东西,它监视上述Kubernetes定制资源,并相应地配置istio入口代理。当然,处理所有传入流量的istio入口代理就是Envoy,它在单独的部署中运行。
示例我们先部署一个httpbin服务,包括ServiceAccount、Service、Deployment资源
apiVersion: v1kind: ServiceAccountmetadata: name: httpbin---apiVersion: v1kind: Servicemetadata: name: httpbin labels ...
Istio流量镜像
Istio的流量镜像也叫影子流量,是将生产的流量镜像拷贝到测试集群或者其他版本中去,简单地说也就是引导实时流量到另一个微服务的版本中去。
将流量路由到reviews:v1版本我们先应用之前的virtual-service-all-v1.yaml,将流量路由到微服务的v1版本
apiVersion: networking.istio.io/v1alpha3kind: VirtualServicemetadata: name: productpagespec: hosts: - productpage http: - route: - destination: host: productpage subset: v1---apiVersion: networking.istio.io/v1alpha3kind: VirtualServicemetadata: name: detailsspec: hosts: - details http: - route: - dest ...
Istio断路器
Istio提供熔断的功能来使你的微服务具有应对故障、潜在峰值和其他网络因素影响的能力。比如熔断器可以允许你限制服务并发连接的次数、调用失败的次数,一旦达到限制的次数,流量就会被Envoy拦截。
部署Deployment资源apiVersion: apps/v1kind: Deploymentmetadata: name: nginxspec: replicas: 1 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx imagePullPolicy: IfNotPresent ports: - containerPort: 80---apiVersion: v1kind: Servicemetadata: name: nginxspec ...
Istio设置请求超时
istio允许用户通过路由规则来设置请求超时,默认情况下,超时是禁用的。
下面我们将reviews的服务超时设置为1秒,然后我们对ratings服务引入2秒的故障延迟。
应用virtualservice规则
由于v1版本的reviews不调用ratings,因为后面需要引入ratings的故障注入,所以我们将请求路由到v2版本的reviews
apiVersion: networking.istio.io/v1alpha3kind: VirtualServicemetadata: name: productpagespec: hosts: - productpage http: - route: - destination: host: productpage subset: v1---kind: VirtualServicemetadata: name: detailsspec: hosts: - details http: - route: - destination: ...
Istio流量转移
基于权重的路由首先应用所有流量到各个微服务的v1版本
apiVersion: networking.istio.io/v1alpha3kind: VirtualServicemetadata: name: productpagespec: hosts: - productpage http: - route: - destination: host: productpage subset: v1---apiVersion: networking.istio.io/v1alpha3kind: VirtualServicemetadata: name: reviewsspec: hosts: - reviews http: - route: - destination: host: reviews subset: v1---apiVersion: networking.istio.io/v1alpha3kind: VirtualServicemetadata: name: ...
Istio故障注入
注入HTTP延迟故障我们对ratings服务注入7s的延迟,当jason用户访问时,有7s的延迟故障
定义VirtualService
apiVersion: networking.istio.io/v1alpha3kind: VirtualServicemetadata: name: ratingsspec: hosts: - ratings http: - match: - headers: end-user: exact: jason fault: delay: fixedDelay: 7s percentage: value: 100 route: - destination: host: ratings subset: v1 - route: - destination: host: ratin ...
Istio-配置请求路由
前言已经部署好了微服务bookinfo,下面开始配置请求路由。
请求路由首先一共4个微服务,分别是productpage(version=v1)、ratings(version=v1)、reviews(version=v1 v2 v3)、details(version=v1),我们需要先应用一个默认的目标规则。
定义DestinationRule
apiVersion: networking.istio.io/v1alpha3kind: DestinationRulemetadata: name: productpagespec: host: productpage subsets: - name: v1 labels: version: v1---apiVersion: networking.istio.io/v1alpha3kind: DestinationRulemetadata: name: detailsspec: host: details subsets: - name: v1 label ...