Opscraft
How SSL/TLS works · Lesson 6 of 8 · 3 min read

TLS in Kubernetes with cert-manager

cert-manager is the standard Kubernetes controller for certificates: it requests, stores and renews them automatically.

apiVersion: cert-manager.io/v1
kind: ClusterIssuer
metadata: { name: letsencrypt-prod }
spec:
  acme:
    server: https://acme-v02.api.letsencrypt.org/directory
    email: [email protected]
    privateKeySecretRef: { name: letsencrypt-account-key }
    solvers:
    - dns01:
        route53:
          region: ap-south-1          # credentials via IRSA on the cert-manager service account
---
apiVersion: cert-manager.io/v1
kind: Certificate
metadata: { name: shop-tls, namespace: shop }
spec:
  secretName: shop-tls                 # a kubernetes.io/tls Secret with tls.crt and tls.key
  dnsNames: [shop.example.com, "*.shop.example.com"]
  issuerRef: { name: letsencrypt-prod, kind: ClusterIssuer }
  privateKey: { algorithm: ECDSA, size: 256, rotationPolicy: Always }
  renewBefore: 720h                    # renew 30 days early
  • Issuers: ACME (Let's Encrypt), AWS Private CA (aws-privateca-issuer), Vault, self-signed/CA for internal PKI.
  • Annotating an Ingress (cert-manager.io/cluster-issuer: letsencrypt-prod) with a tls: section creates the Certificate automatically — the pattern for ingress-nginx.
  • Secrets of type kubernetes.io/tls hold tls.crt (full chain) and tls.key, referenced by Ingresses or mounted into pods.
  • Apps must reload renewed certificates — Nginx/Envoy/ingress controllers handle it; custom apps may need a file watcher or a rolling restart (Reloader).
  • Monitor certmanager_certificate_expiration_timestamp_seconds and certmanager_certificate_ready_status in Prometheus.

Note that with an ALB you'd normally use ACM rather than cert-manager — ALBs can't use Kubernetes Secrets directly. cert-manager shines with NGINX/Envoy ingress, internal mTLS and service certificates.

Enlarge diagramCertificate objector an Ingress annotationcert-managertalks to the issuerIssuerLet's Encrypt, AWS Private CA,VaultSecret kubernetes.io/tlstls.crt and tls.keyIngress / appreloads the new certificateRenewalrepeats before expiry123456
Figure 1. cert-manager in a cluster: you declare the certificate you want, and it obtains, stores and renews it, 30 days before expiry by default in this example.
Swipe sideways to see all of it, or tap to open it full screen.