Ingress
要整合Cert-Manager
的憑證,會因為各方實作方式不同,ingress
設定會略有不同。
下面以 nginx ingress 整合憑證前後之範例:
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: simple-fanout-example
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- host: foo.bar.com
http:
paths:
- path: /foo
backend:
serviceName: service1
servicePort: 4200
- path: /bar
backend:
serviceName: service2
servicePort: 8080
下面,透過Cert-manager
申請與取得的憑證資訊,存放於 K8s secret 裏頭。
apiVersion: v1
kind: Secret
metadata:
name: testsecret-tls
namespace: default
data:
tls.crt: base64 encoded cert
tls.key: base64 encoded key
type: kubernetes.io/tls
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: tls-example-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
tls:
- hosts:
- sslexample.foo.com
secretName: testsecret-tls
rules:
- host: foo.bar.com
http:
paths:
- path: /foo
backend:
serviceName: service1
servicePort: 4200
- path: /bar
backend:
serviceName: service2
servicePort: 8080
此處要注意的重點就是:spec.tls.hosts
\ secretName
這裡指定了使用testsecret-tls
此張憑證,於此網站入口ingress
使用,如此網站拜訪者即可使用具備 SSL安全通道的HTTPS 入口網站服務。