微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

idou老师教你学Istio 09: 如何用Istio实现K8S Ingress流量管理

前言

在Istio的世界里,如果想把外部的请求流量引入网格,你需要认识并会学会配置Istio Ingress Gateway

什么是Ingress Gateway

由于Kubernetes Ingress API只能支持最基本的HTTP路由,使用Kubernetes Ingress资源来配置外部流量的方式不能满足需求。因此Istio v1alpha3 routing API引入新的Istio Ingress Gateway取代Kubernetes Ingress。
Gateway为HTTP/TCP流量配置了一个负载均衡,用于承载网格边缘的进入和发出连接。在同一个网格中可以有多个不同的gateway存在。这一规范中描述了一系列开放端口,以及这些端口所使用的协议、负载均衡的 SNI 配置等内容用户可以利用标准的Istio 路由规则控制HTTP和TCP请求进入网格。

从下图可以看到Istio gateway在整个网格中的使用情况:

idou老师教你学Istio 09: 如何用Istio实现K8S Ingress流量管理

如何配置Gateway控制Ingress流量

如果你已经安装好了bookinfo的应用,为了能在外部访问bookinfo中的productpage服务,只需要配置Gateway和相关的VirtualService。

一个简单的gateway配置一个负载均衡使访问bookinfo.com的外部http流量能够进入网格:

apiVersion: networking.istio.io/v1alpha3
kind: Gateway
Metadata:
name: bookinfo-gateway
spec:
selector:
istio: ingressgateway
servers:

  • hosts:
    • bookinfo.com
      port:
      number: 80
      name: http
      protocol: HTTP
      为了配置相应的路由,需要为相同的host定义一个VirtualService 并且用配置中gateways的字段绑定到刚才创建的Gateway:

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
Metadata:
name: bookinfo
spec:
hosts:

  • bookinfo.com
    gateways:
  • bookinfo-gateway # <---- 绑定gateway
  • mesh # <----对内部通信进行流量控制
    http:
  • match:
    • uri:
      exact: /productpage
      route:
    • destination:
      host: productpage
      port:
      number: 9080
      这样就达到了在外网开放productpage服务的目的。

如何用HTTPS加密Gateway?

我们也可以为服务启用TLS保护,以HTTPS的形式对网格外提供服务。

首先需要使用工具生成客户端和服务器端的证书和密钥。然后使用密钥和证书作为输入,创建一个Secret。

$ kubectl create -n istio-system secret tls istio
-ingressgateway-certs --key key.pem --cert cert.p
em
接下来修改Gateway对象,为Ingress gateway开放一个443端口,用于提供HTTPS服务:

apiVersion: networking.istio.io/v1alpha3
kind: Gateway
Metadata:
name: bookinfo-gateway
spec:
selector:
istio: ingressgateway
servers:

  • hosts:
    • bookinfo.com
      port:
      number: 80
      name: http
      protocol: HTTP
    • hosts:
      • "*"
        port:
        number: 443
        name: https
        protocol: HTTPS
        tls:
        mode: SIMPLE
        serverCertificate: /etc/istio/ingressgateway-certs/tls.crt
        privateKey: /etc/istio/ingressgateway-certs/tls.key
        这样简单的配置就可以通过HTTPS协议访问bookinfo.com了。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐