cert-manager is a powerful and extensible X.509 certificate controller for Kubernetes and OpenShift workloads. It will obtain certificates from a variety of Issuers, both popular public Issuers as well as private Issuers, and ensure the certificates are valid and up-to-date, and will attempt to renew certificates at a configured time before expiry.
cert-manager can obtain certificates from a variety of certificate authorities, including: Let's Encrypt, HashiCorp Vault, CyberArk Certificate Manager and private PKI.
自動為網站設定 HTTPS(如 myapp.example.com)
搭配 Let's Encrypt 或企業內部 CA 自動簽發憑證
不需手動更新 TLS 憑證
K8s 中的 webhook 需要使用 TLS 憑證與 API Server 建立安全連線
cert-manager 自動為 webhook 產生與輪換 TLS 憑證
OpenShift 使用
Route
對外公開服務,想搭配 cert-manager 來簽發 TLS 憑證
將 cert-manager 產出的 TLSSecret
內容寫入 Route 的.spec.tls
微服務之間通訊需要雙向 TLS 驗證(例如 service mesh、金融場景)
cert-manager 為每個 service 簽發 client certificate
部署新環境時,自動幫 webhook、UI、API 建立憑證
GitOps 工具(如 ArgoCD、Flux)配合 cert-manager 自動申請/更新憑證
企業已經有內部 CA(如 Microsoft AD CS、Venafi、Vault PKI),想讓 cert-manager 發 CSR 給它簽發憑證
增強整個集群的 TLS 信任鏈與審計能力
cert-manager 也可以簽發 JWT 憑證(非 TLS),搭配 OIDC、SPIFFE 使用
用於 workload identity、service identity(特別是在零信任架構中)
cert-manager 可搭配 Kubernetes Event、Prometheus、Alertmanager 對憑證快過期發出告警
也可用 GitOps 方式監看哪些證書即將過期
在 OpenShift 中使用 cert-manager 為一個 Route 自動配置 TLS 憑證,需要進行以下操作:
# 1-1 自簽 CA Secret(CA 憑證 + 私鑰)
apiVersion: v1
kind: Secret
metadata:
name: my-ca-secret
namespace: cert-manager
type: kubernetes.io/tls
data:
tls.crt: <base64-encoded-ca-cert>
tls.key: <base64-encoded-ca-key>
# 1-2 ClusterIssuer(用上面的自簽 CA)
apiVersion: cert-manager.io/v1
kind: ClusterIssuer
metadata:
name: my-selfsigned-clusterissuer
spec:
ca:
secretName: my-ca-secret
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
name: my-service-cert
namespace: my-namespace
spec:
secretName: my-service-tls # 憑證與金鑰會存在這個 Secret 中
duration: 2160h # 有效期 90 天
renewBefore: 360h # 15 天前開始續約
commonName: my-service.example.com
dnsNames:
- my-service.example.com
issuerRef:
name: my-selfsigned-clusterissuer
kind: ClusterIssuer
apiVersion: route.openshift.io/v1
kind: Route
metadata:
name: my-service
namespace: my-namespace
spec:
host: my-service.example.com
to:
kind: Service
name: my-service
port:
targetPort: 8080
tls:
termination: edge
key: |
<填入自動產生 Secret 中的 key>
certificate: |
<填入自動產生 Secret 中的 cert>
oc get secret my-service-tls -n my-namespace -o jsonpath='{.data.tls\.key}' | base64 -d > tls.key
oc get secret my-service-tls -n my-namespace -o jsonpath='{.data.tls\.crt}' | base64 -d > tls.crt