Istio:Gateway设计与实现

目录

  • Gateway简介
  • Gateway vs Kubernetes Ingress
  • Gateway原理及实现

Gateway简介

在Istio中, Gateway控制着网格边缘的服务暴露。

Gateway也可以看作网格的负载均衡器, 提供以下功能:

  • 1) L4-L6的负载均衡
  • 2) 对外的mTLS

Istio服务网格中, Gateway可以部署任意多个,可以共用一个,也可以每个租户、 namespace单独隔离

标题

Gateway根据流入流出方向分为ingress gateway和egress gateway

Ingress gateway:

  • 控制外部服务访问网格内服务,配合VirtualService

 Egress gateway:

  • 控制网格内服务访问外部服务, 配合DestinationRule ServiceEntry使用

Gateway vs Kubernetes Ingress

Kubernetes Ingress集群边缘负载均衡, 提供集群内部服务的访问入口,仅支持L7负载均衡, 功能单一
Istio 1.0以前,利用Kubernetes Ingress实现网格内服务暴露。但是Ingress无法实现很多功能:

  • 1) L4-L6负载均衡
  • 2) 对外mTLS
  • 3) SNI的支持
  • 4) 其他istio中已经实现的内部网络功能: Fault Injection,Traffic Shifting, Circuit Breaking, Mirroring
     

为了解决这些这些问题, Istio在1.0版本设计了新的v1alpha3API。

  1. Gateway允许管理员指定L4-L6的设置:端口及TLS设置。
  2.  对于ingress 的L7设置, Istio允许将VirtualService与Gateway绑定起来。
  3. 分离的好处:用户可以像使用传统的负载均衡设备一样管理进入网格内部的流量,绑定虚拟IP到虚拟服务器上 。便于传统技术用户无缝迁移到微服务

Gateway原理及实现

Gateway原理及实现
Gateway原理及实现

Gateway 与 普通sidecar均是使用Envoy作为proxy实行流量控制。

Pilot为不同类型的proxy生成相应的配置, Gateway的类型为router, sidecar的类型为sidecar。

Ingress Gateway 启动参数:

Ingress Gateway 启动参数

Sidecar启动参数:

Sidecar启动参数

Pilot如何得知proxy类型?

kubectl get crd gateways.networking.istio.io 验证

kubectl get crd gateways.networking.istio.io 验证

Istio networking所有配置API定义:

https://github.com/istio/api/tree/master/networking/v1alpha3

Istio networking所有配置API定义
Istio networking所有配置API定义
Istio networking所有配置API定义
Istio networking所有配置API定义

Gateway配置下发:

Gateway配置下发

Gateway demo演示

  • 控制Ingress HTTP流量
  • 利用HTTPS保护后端服务
  • mTLS
  • 控制egress流量

理解外部请求如何到达应用

  • 1) Client发起请求到特定端口
  • 2) Load Balancer 监听在这个端口, 并转发到后端
  • 3) 在Istio中, LB将请求转发到IngressGateway 服务
  • 4) Service将请求转发到IngressGateway pod
  • 5) Pod 获取Gateway 和 VirtualService配置,获取端口、协议、证书,创建监听器
  • 6) Gateway pod 根据路由将请求转发到应用pod( 不是service)

控制Ingress HTTP流量

HTTPS termination

生成证书
https://istio.io/docs/tasks/traffic-management/secure-ingress/#generate-client-andserver-certificates-and-keys

创建secret:名称一定是istio-ingressgateway-certs,否则mount不上

$ kubectl create -n istio-system secret tls istio-ingressgateway-certs --key
httpbin.example.com/3_application/private/httpbin.example.com.key.pem --cert
httpbin.example.com/3_application/certs/httpbin.example.com.cert.pem

创建应用
$ kubectl apply -f samples/httpbin/httpbin.yaml
创建路由规则
$ kubectl apply -f samples/httpbin/httpbin-gateway-https.yaml

通过HTTPS访问
$ curl -v -HHost:httpbin.example.com --resolve httpbin.example.com:31390:100.109.176.196 --
cacert httpbin.example.com/2_intermediate/certs/ca-chain.cert.pem
https://httpbin.example.com:31390/status/418

 mTLS

创建包含CA证书的secret

kubectl create -n istio-system secret generic istio-ingressgateway-ca-certs --fromfile=httpbin.example.com/2_intermediate/certs/ca-chain.cert.pem

更新Gateway TLS setting

更新Gateway TLS setting
通过HTTPS访问

Istio访问外部服务

Istio网格内默认不能访问外部服务,如果需要访问外部服务有三种方式:

创建应用时指定pod annotation

traffic.sidecar.istio.io/includeOutboundIPRanges: "127.0.0.1/24,10.96.0.1/24“

创建ServiceEntry

  •  允许集群内访问外部服务http://httpbin.org:80

通过egress gateway控制访问外部服务

通过egress gateway控制访问外部服务

 通过egress gateway控制访问外部服务

 通过egress gateway控制访问外部服务
发布了389 篇原创文章 · 获赞 1041 · 访问量 163万+

猜你喜欢

转载自blog.csdn.net/fly910905/article/details/103969825