Skip to main content

cert-manager

cert-manager adds certificates and certificate issuers as resource types in Kubernetes clusters, and simplifies the process of obtaining, renewing and using those certificates.

It can issue certificates from a variety of supported sources, including Let’s Encrypt, HashiCorp Vault, and Venafi as well as private PKI.

It will ensure certificates are valid and up to date, and attempt to renew certificates at a configured time before expiry.

-- cert-manager | cert-manager

Installation

kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.7.1/cert-manager.yaml

Ref: Kubectl apply | cert-manager

Creating Issuers/ClusterIssuers

Issuer vs ClusterIssuer

An Issuer is a namespaced resource, and it is not possible to issue certificates from an Issuer in a different namespace. This means you will need to create an Issuer in each namespace you wish to obtain Certificates in.

If you want to create a single Issuer that can be consumed in multiple namespaces, you should consider creating a ClusterIssuer resource. This is almost identical to the Issuer resource, however is non-namespaced so it can be used to issue Certificates across all namespaces.

-- Issuer | cert-manager

Following example creates an ACME ClusterIssuer using Cloudflare as DNS01 challenge provider:

apiVersion: v1
kind: Secret
metadata:
name: cloudflare-api-token
namespace: cert-manager
type: Opaque
stringData:
api-token: YOUR_TOKEN

Ref: Cloudflare | cert-manager

Creating certificates

You can use following example to issue a certificate:

apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
name: example-com-wildcard
spec:
secretName: example-com-wildcard-tls
renewBefore: 360h # 15d
dnsNames:
- example.com
- "*.example.com"
issuerRef:
name: letsencrypt-prod
kind: ClusterIssuer

Ref: Certificate Resources | cert-manager

Using certificates

You can refer to a certificate in Ingress by using secretName like following example:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: whoami
annotations:
kubernetes.io/ingress.class: "traefik"
spec:
tls:
- hosts:
- whoami.example.com
secretName: example-com-wildcard-tls #(1)
rules:
- host: whoami.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: whoami
port:
number: 80
  1. Refer to the certificate you created in the previous step