cert-manager

cert-manager 是一种自动执行证书管理的工具,它可以与 Istio Gateway 集成以管理 TLS 证书。

配置

查阅 cert-manager 安装文档来快速开始,它无需特殊配置即可与 Istio 一起使用。

使用

Istio Gateway

cert-manager 可用于向 Kubernetes 写入 Secret 秘钥,Gateway 可以引用该秘钥。首先,请按照 cert-manager 文档中的说明配置 Certificate 资源。Certificate 应该创建在与 istio-ingressgateway Deployment 相同的命名空间。例如, 一个 Certificate 可能看起来像下边这样:

  1. apiVersion: cert-manager.io/v1alpha2
  2. kind: Certificate
  3. metadata:
  4. name: ingress-cert
  5. namespace: istio-system
  6. spec:
  7. secretName: ingress-cert
  8. commonName: my.example.com
  9. dnsNames:
  10. - my.example.com
  11. ...

一旦创建了 Certificate 资源,我们就能在 istio-system 命名空间中看到创建的秘钥,接着就可以在 Gateway 的 tls 配置下的 cresentialName 字段中引用它:

  1. apiVersion: networking.istio.io/v1alpha3
  2. kind: Gateway
  3. metadata:
  4. name: gateway
  5. spec:
  6. selector:
  7. istio: ingressgateway
  8. servers:
  9. - port:
  10. number: 443
  11. name: https
  12. protocol: HTTPS
  13. tls:
  14. mode: SIMPLE
  15. credentialName: ingress-cert # This should match the Certifcate secretName
  16. hosts:
  17. - my.example.com # This should match a DNS name in the Certificate

Kubernetes Ingress

cert-manager 通过在 Ingress 对象上配置注解,做到与 Kubernetes Ingress 的直接集成。如果使用此方法,则 Ingress 必须与 istio-ingressgateway Deployment 位于同一命名空间中,因为 Secret 只能在同一命名空间中被读取。

或者,也可以按照 Istio Gateway 部分的描述创建 Certificate,然后在 Ingress 对象中引用它:

  1. apiVersion: extensions/v1beta1
  2. kind: Ingress
  3. metadata:
  4. name: ingress
  5. annotations:
  6. kubernetes.io/ingress.class: istio
  7. spec:
  8. rules:
  9. - host: my.example.com
  10. http: ...
  11. tls:
  12. - hosts:
  13. - my.example.com # This should match a DNS name in the Certificate
  14. secretName: ingress-cert # This should match the Certifcate secretName