Istio网关Gateway 启用TLS

Istio网关Gateway概述


Istio网关Gateway是一个负责处理南北向流量的组件,它通常会暴露服务网格内部的服务,以便外部的请求能够访问到服务网格中的服务。Istio网关Gateway支持多种协议,包括HTTP、HTTPS和GRPC等。

在Istio网关Gateway中,每个服务器都包含一个或多个端口,每个端口都定义了一种协议和相应的配置。Istio网关Gateway还可以定义多个TLS证书,以便对传输的数据进行加密和解密。

在配置Istio网关Gateway时,我们需要指定其所使用的负载均衡算法和服务发现机制。Istio网关Gateway支持多种服务发现机制,包括Kubernetes服务发现、Consul服务发现和Eureka服务发现等。

先来部署有TLS的网关。
1.生成密钥对

首选来生成密钥对,-keyout是生成私钥。-out是公钥,生成的密钥对。生成好了要放在指定的目录下,在/etc/istio/ingressgateway-certs/。

复制代码
[root@k8s-master ~]# mkdir -p /etc/istio/ingressgateway-certs
[root@k8s-master ~]# openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/istio/ingressgateway-certs/mykey.key -out /etc/istio/ingressgateway-certs/mycrt.crt -subj "/CN=mytest/O=my-test"
Generating a 2048 bit RSA private key
..............................................................................+++
........................+++
writing new private key to '/etc/istio/ingressgateway-certs/mykey.key'
-----
[root@k8s-master ~]# ls /etc/istio/ingressgateway-certs
mycrt.crt  mykey.key

这个证书并不是合法的CA颁发的,而是我们自己生成的。

2.创建tls类型的secret

复制代码
[root@k8s-master ~]# kubectl create secret generic istio-ingressgateway-certs --from-file /etc/istio/ingressgateway-certs/mykey.key --from-file /etc/istio/ingressgateway-certs/mycrt.crt -n istio

这里的证书正常情况下是CA帮我们颁发的,只不过我们这里并没有使用到CA。

复制代码
serverCertificate: /etc/istio/ingressgateway-certs/mycrt.crt
privateKey: /etc/istio/ingressgateway-certs/mykey.key

多套证书,基于多个域名


其实也就是两套证书,两套证书分配给不同的域名。

上面是直接服务器端生成了公钥和私钥。如果是生产环境那么就需要去购买证书,购买证书可以到阿里云等厂商。

前提

  • EKS集群可用
  • istio-gateway可用

创建TLS证书secret

复制代码
kubectl create secret generic shanhaitls-credential -n istio-system \
--from-file=cert=$Path/certs/server.cer \
--from-file=key=$Path/certs/server.key

Gateway添加TLS配置

复制代码
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: swbom-g-gateway
  namespace: istio-system
spec:
  selector:
    istio: ingressgateway # use Istio default gateway implementation
  servers:
  - port:
      number: 80
      name: http
      protocol: HTTP
    hosts:
    - "swbom-dev-g.shanhai.huawei.com"
    - "swbom-g-test-kuboard-elb.shanhai.huawei.com"
  - port:
      number: 443
      name: https
      protocol: HTTPS
    tls:
      mode: SIMPLE
      credentialName: shanhaitls-credential # must be the same as secret
    hosts:
    - "swbom-dev-g.shanhai.huawei.com"
    - "swbom-g-test-kuboard-elb.shanhai.huawei.com"
---

Gateway配置示例

以下是一个使用Istio Gateway进行南北流量管理的示例:

复制代码
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: my-gateway
spec:
  selector:
    istio: ingressgateway
  servers:
  - port:
      number: 80
      name: http
      protocol: HTTP
    hosts:
    - my-service.com
    tls:
      mode: SIMPLE
      serverCertificate: /etc/certs/server.pem
      privateKey: /etc/certs/private_key.pem
  - port:
      number: 443
      name: https
      protocol: HTTPS
    hosts:
    - my-service.com
    tls:
      mode: SIMPLE
      serverCertificate: /etc/certs/server.pem
      privateKey: /etc/certs/private_key.pem
  - port:
      number: 8443
      name: https-admin
      protocol: HTTPS
    hosts:
    - my-admin.com
    tls:
      mode: SIMPLE
      serverCertificate: /etc/certs/server.pem
      privateKey: /etc/certs/private_key.pem
  - port:
      number: 8080
      name: grpc
      protocol: GRPC
    hosts:
    - my-service.com
    tls:
      mode: SIMPLE
      serverCertificate: /etc/certs/server.pem
      privateKey: /etc/certs/private_key.pem

在上述示例中,我们首先定义了一个名为my-gateway的Gateway对象。该对象有一个标签选择器istio: ingressgateway,用于将其指定为Istio Ingress Gateway。

在该Gateway对象中,我们定义了四个服务器,分别处理不同的端口和协议。

其中,第一个服务器用于处理HTTP流量,第二个服务器用于处理HTTPS流量,第三个服务器用于处理HTTPS管理员流量,第四个服务器用于处理GRPC流量。每个服务器都定义了一个名为port的子对象,用于指定其所使用的端口、协议和端口名称。每个服务器还定义了一个名为hosts的子对象,用于指定其所支持的主机名。此外,每个服务器还定义了一个名为tls的子对象,用于指定其所使用的TLS证书的相关配置。

相关推荐
telllong6 天前
3分钟理解服务网格Istio
云原生·istio
heimeiyingwang16 天前
【架构实战】Service Mesh深度对比:Istio vs Linkerd
架构·istio·service_mesh
crossoverJie18 天前
从企业版 Istio 迁移到社区版:一场给高速行驶汽车换轮胎的实践
云原生·汽车·istio
刘~浪地球20 天前
云原生与容器--Service Mesh (Istio) 入门实战
云原生·istio·service_mesh
pl4H522a61 个月前
istio初探以及解决http-426的问题
http·kubernetes·istio
人间打气筒(Ada)1 个月前
go实战案例:如何通过 Service Meh 实现熔断和限流
java·开发语言·golang·web·istio·service mesh·熔断限流
岁岁种桃花儿1 个月前
kubenetes从入门到上天系列第二十六篇:Kubernetes的Istio服务网格实战
java·kubernetes·istio
人间打气筒(Ada)1 个月前
go实战案例:如何在 Go-kit 和 Service Meh 中进行服务注册与发现?
开发语言·后端·golang·istio·go-kit
lpruoyu2 个月前
【云原生】可观测性系统—Istio
云原生·istio
Gold Steps.2 个月前
K8S结合Istio深度实操
云原生·kubernetes·istio