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证书的相关配置。

相关推荐
小北方城市网9 天前
第 5 课:服务网格(Istio)实战|大规模微服务的流量与安全治理体系
大数据·开发语言·人工智能·python·安全·微服务·istio
没有bug.的程序员9 天前
Istio 架构全景解析:控制面 vs 数据面、核心组件与流量路径深度拆解
微服务·云原生·架构·istio·架构设计·envoy·servicemesh
没有bug.的程序员9 天前
为什么会出现 Service Mesh:从 Spring Cloud 到 Sidecar 的演进逻辑
spring cloud·微服务·云原生·istio·service_mesh·架构演进·sidecar
虫小宝11 天前
导购返利APP服务网格实践:基于Istio的微服务流量管理与监控
微服务·云原生·istio
汪碧康17 天前
【k8s-1.34.2安装部署】十.gateway Api v1.4.0和istio安装
云原生·容器·kubernetes·gateway·istio·cilium·xkube
一起养小猫19 天前
【探索实战】Kurator统一流量治理深度实践:基于Istio的跨集群服务网格
java·云原生·istio
一起养小猫1 个月前
【前瞻创想】Kurator生态创新展望:AI原生时代的多集群管理范式
云原生·华为云·istio·ai-native·kurator
一起养小猫1 个月前
【贡献经历】从零到贡献者:我的Kurator开源社区参与之旅
分布式·物联网·云原生·开源·华为云·istio·kurator
古城小栈1 个月前
微服务网格:Istio 流量管理实战
微服务·架构·istio
聊询QQ:276998851 个月前
Matlab/Simulink 半车主动悬架建模:ADRC 与 PID 的碰撞之旅
istio