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

栏目: 后端 · 发布时间: 7年前

内容简介:由于 Kubernetes Ingress API 只能支持最基本的 HTTP 路由,使用 Kubernetes Ingress资源来配置外部流量的方式不能满足需求。因此 Istio v1alpha3 routing API 引入新的 Istio Ingress Gateway 取代 Kubernetes Ingress。Gateway 为 HTTP/TCP 流量配置了一个负载均衡,用于承载网格边缘的进入和发出连接。在同一个网格中可以有多个不同的 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。

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.pem
复制代码

接下来修改 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 了。


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Modeling the Internet and the Web

Modeling the Internet and the Web

Pierre Baldi、Paolo Frasconi、Padhraic Smyth / Wiley / 2003-7-7 / USD 115.00

Modeling the Internet and the Web covers the most important aspects of modeling the Web using a modern mathematical and probabilistic treatment. It focuses on the information and application layers, a......一起来看看 《Modeling the Internet and the Web》 这本书的介绍吧!

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换