cert-manager¶
cert-manager and the two Let's Encrypt ClusterIssuers every certificate in the cluster is issued from. Both solve the DNS-01 challenge through Cloudflare, so nothing has to be reachable from the internet. The certificates themselves live with their consumers; the gateways' wildcards are in network.
Manifests: kubernetes/apps/cert-manager.
Apps¶
Both Kustomizations are in cert-manager/ks.yaml.
| App | What it does | Notes |
|---|---|---|
cert-manager |
The chart and its alert rules | Installed by bootstrap before Flux; opts out of substitution |
cert-manager-issuers |
letsencrypt-production, letsencrypt-staging and the Cloudflare token they share |
dependsOn cert-manager for the CRD |
How it fits together¶
- Bootstrap installs the chart first (
bootstrap/kubernetes/helmfile/apps.yaml), reading the version from ocirepository.yaml and the values from helmrelease.yaml. Flux then adopts that release. Bootstrap reads those files verbatim, which is whycert-manageropts out of${VAR}substitution (see clusters).cert-manager-issuersdoesn't: its zones come fromcluster-settings. - The issuers are a second Kustomization because Flux dry-runs every resource before applying any. In one Kustomization with the chart, a missing
ClusterIssuerCRD would fail the dry-run before the HelmRelease was ever applied. cert-manager-issuersis Ready onceletsencrypt-productionhas registered its ACME account. AClusterIssuerhas no status Flux understands on its own, sohealthCheckExprsreads itsReadycondition. The staging issuer is left out ofhealthCheckson purpose: nothing issues from it day to day, and an outage of Let's Encrypt's staging endpoint shouldn't mark the Kustomization failed.- The Cloudflare token is the
API_TOKENfield of the 1Password itemcloudflare-tunnel, which other apps read too (grep -rl "key: cloudflare" kubernetes/apps). Rotating it re-renders all of their Secrets. cert-manager reads the Secret on every challenge, so it needs no restart.
Operating¶
kubectl get clusterissuer # both should be Ready
kubectl get certificate,certificaterequest -A # what is issued, and what is stuck
kubectl get order,challenge -A # an issuance in progress
kubectl logs -n cert-manager deploy/cert-manager # the controller: ACME and DNS-01 errors
just k8s sync-hr cert-manager cert-manager
Try a new Certificate against letsencrypt-staging first. Its rate limits are far higher, and its certificates are not trusted by browsers.
Gotchas¶
- A new domain goes into
dnsZonesof both issuers in clusterissuer.yaml, as its${DOMAIN_*}variable. ACertificatefor a zone neither lists is never issued: its challenge finds no matching solver. - Propagation checks go to Cloudflare's DNS-over-HTTPS resolvers only (
dns01RecursiveNameservers,dns01RecursiveNameserversOnly). Before asking Let's Encrypt to validate, cert-manager looks for the challenge record itself. The cluster's and the LAN's resolvers don't reliably show that record, so the check bypasses both. Don't remove the two values: issuance can then stall waiting for a record that is already public. - Depend on
cert-manager, not oncert-manager-issuers, for the CRDs. A chart that creates its ownIssuerandCertificates needs only the first. To find what depends on either:grep -rn "name: cert-manager" kubernetes/apps --include=ks.yaml. - The CRDs are chart templates (
crds.enabled), protected by the chart's defaultcrds.keep: true, which putshelm.sh/resource-policy: keepon each one. Don't setcrds.keep: false: uninstalling the release would then delete everyCertificatein the cluster. See helm-crds. - The webhook runs two replicas behind a PodDisruptionBudget. It validates every cert-manager resource, Flux's dry-runs included, so a single replica on a draining node would fail every Kustomization that holds a
Certificateuntil it came back. CertManagerCertExpirySoonfires a week after a missed renewal, not at a fixed time before expiry. It compares against each certificate's own renewal time (status.renewalTime, from itsrenewBefore), so certificates that renew 15 days early, like the CNPG Barman plugin's, don't fire before they are due. A certificate whoserenewBeforeis less than 7 days would expire before the alert fires.CertManagerAbsentkeys onjob="cert-manager". The chart's ServiceMonitor takes the job name from theapp.kubernetes.io/namelabel, which iscert-managerfor the controller only (the webhook and cainjector report under their own names).