Cert-Manager: automate your certificate management for Kubernetes

Introduction
Cert-Manager is a native Kubernetes certificate management controller. It can help with issuing certificates from a variety of sources, such as Let's Encrypt, HashiCorp Vault, a simple signing key pair, or self-signed.
It will ensure certificates are valid and up to date, and attempt to renew certificates at a configured time before expiry.
Installation
We will install cert-manager using Helm. Below is the configuration values.yaml we will use to configure it.
Configuration
Let's create a file named values-override.yaml with minimal values to install cert-manager following content:
Install with Helm
Let's run the following command to install cert-manager:
Configuring Issuers
Issuers, and ClusterIssuers, are resources that represent certificate authorities (CAs) that are able to generate signed certificates by honoring certificate signing requests. All cert-manager certificates require a referenced issuer that is in a ready condition to attempt to honor the request.
Difference between Issuer and ClusterIssuer
The difference between Issuer and ClusterIssuer is that ClusterIssuer is cluster scoped, while Issuer is namespace scoped.
Cloudflare & Let's Encrypt with ClusterIssuer
Here is an example of a ClusterIssuer that uses Cloudflare for DNS01 challenge validation with Let's Encrypt.
graph LR
CM[cert-manager] -->|1. Creates Challenge| LE[Let's Encrypt]
CM -->|2. Creates DNS Record| CF[Cloudflare DNS]
LE -->|3. Verifies DNS Record| CF
LE -->|4. Signs Certificate| CM
CM -->|5. Stores Certificate| S[k8s Secret] We'll see here only the ClusterIssuer configuration for simplicity (one wildcard certificate for all subdomains of mydomain.com). But the process is close to the same for a single certificate.
Let's create the ClusterIssuer containing Cloudflare information the the ACME protocol:
|
Here we're using Cloudflare, but there are many other supported providers.
Then deploy the configuration:
Gateway API Support
Cert-manager can also integrate with the Kubernetes Gateway API or Ingress to automatically manage certificates for your Gateways.
graph TD
User -->|1. Creates| G[Gateway]
G -.->|Annotation: cluster-issuer| CI[ClusterIssuer]
CM[cert-manager] -->|2. Watches| G
CM -->|3. Creates| C[Certificate]
CI -->|4. Signs| C
CM -->|5. Saves to| S[Secret]
G -->|6. TLS Config References| S Gateway TLS Configuration
This gateway configuration uses the cloudflare-letsencrypt ClusterIssuer we defined earlier to automatically provision certificates for exposed services. Here Cilium is used as the GatewayClass, and as you can see, we simply have to add the cert-manager.io/cluster-issuer annotation to the Gateway resource to enable automatic certificate management:
At this point, cert-manager should be ready to issue certificates for your domains. You can validate that the ClusterIssuer is ready by running (wait 1 min or 2, it can take some time):
And your certificate should be present:
Now you should be able to access your services using HTTPS :)
Self-Signed Certificates
Self-signed certificates are useful for internal testing, development environments, or when you don't need a public trust chain. They are signed by a private key that you control, rather than a well-known Certificate Authority (CA).
Note
Self-signed certificates are not trusted by browsers and will result in security warnings. They are only suitable for internal use.
How it Works
The process involves creating a self-signed Issuer (or ClusterIssuer) which then signs the Certificate request. The resulting certificate is stored in a Kubernetes Secret.
graph LR
A[Issuer/ClusterIssuer] -->|Signs| B[Certificate]
B -->|Stored in| C[Secret]
C -->|Used by| D[Ingress/Gateway] Configuration
SelfSigned Issuer
First, let's create a self-signed Issuer. This tells cert-manager that it can sign certificates itself.
Certificate
Then, let's create a Certificate resource that references the generic self-signed issuer.
Local Gateway TLS
This example sets up a local gateway listening on HTTPS, managing certificates via a secret in the cert-manager namespace.
Warning
If your gateway is not in the cert-manager namespace, you will need to create a ReferenceGrant to allow the gateway to access the secret.