5.2.1 为入口网关配置TLS

创建一个Kubernetes secret对象,用于保存服务器的证书和私钥。具体来说就是使用kubectl命令在命名空间istio-system中创建一个secret对象,命名为istio-ingressgateway-certs。Istio Gateway会自动载入这个secret:


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

这里的secret必须在istio-system命名空间中,并且命名为istio-ingressgateway-certs,否则就不会被正确载入,也就无法在Istio gateway中使用了。

然后,定义一个Gateway对象,其中包含了使用443端口的server部分。证书的私钥的位置必须是/etc/istio/ingressgateway-certs,否则Gateway无法载入,具体代码可参见目录mtls-go-example/https下的文件mygateway.yaml:


kubectl apply -f - <<EOF
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: mygateway
spec:
  selector:
    istio: ingressgateway # 使用 Istio 默认的 Gateway
  servers:
  - port:
      number: 443
      name: https
      protocol: HTTPS
    tls:
      mode: SIMPLE
      serverCertificate: /etc/istio/ingressgateway-certs/tls.crt
      privateKey: /etc/istio/ingressgateway-certs/tls.key
    hosts:
    - "httpbin.example.com"
EOF