Guto Carvalho # 2022-21-08 @ BSB
Guto Carvalho # 2022-21-08 @ BSB

K8S: Instalando Cert-Manager e issuers LetsEncrypt

by

Aprenda a instalar ao cert-manager no k8s de forma objetiva e rápida!

Instalando CertManager

Instale o CustomResourceDefinition separadamente

$ kubectl apply --validate=false -f https://github.com/jetstack/cert-manager/releases/download/v1.5.4/cert-manager.crds.yaml

Crie o namespace para o cert-manager

$ kubectl create namespace cert-manager

Adicione o repositório helm

$ helm repo add jetstack https://charts.jetstack.io

Atualize os indices do helm

$ helm repo update

Instale o cert-manager via helm

$ helm install \
  cert-manager jetstack/cert-manager \
  --namespace cert-manager \
  --version v1.5.4

Crie o issuer para letsencrypt production

$ vim issuer-prod.yaml

Insira o conteúdo

apiVersion: cert-manager.io/v1
kind: ClusterIssuer
metadata:
  name: letsencrypt-prod
spec:
  acme:
    # You must replace this email address with your own.
    # Let's Encrypt will use this to contact you about expiring
    # certificates, and issues related to your account.
    email: certmanager@gutocarvalho.net
    server: https://acme-v02.api.letsencrypt.org/directory
    privateKeySecretRef:
      # Secret resource that will be used to store the account's private key.
      name: letsencrypt-production
    # Add a single challenge solver, HTTP01 using nginx
    solvers:
    - http01:
        ingress:
          class: nginx

Aplicando

$ kubectl create -f issuer-prod.yaml

Criando o issuer para letsencrypt staging

vim issuer-staging.yaml

Insira o conteúdo

apiVersion: cert-manager.io/v1
kind: ClusterIssuer
metadata:
  name: letsencrypt-staging
spec:
  acme:
    # You must replace this email address with your own.
    # Let's Encrypt will use this to contact you about expiring
    # certificates, and issues related to your account.
    email: nativetrail@gutocarvalho.net
    server: https://acme-staging-v02.api.letsencrypt.org/directory
    privateKeySecretRef:
      # Secret resource that will be used to store the account's private key.
      name: letsencrypt-staging
    # Add a single challenge solver, HTTP01 using nginx
    solvers:
    - http01:
        ingress:
          class: nginx

Aplicando

$ kubectl create -f issuer-staging.yaml

Prontinho!

Annotations

Para production

cert-manager.io/cluster-issuer=letsencrypt-prod
kubernetes.io/ingress.class=nginx

Para staging

cert-manager.io/cluster-issuer=letsencrypt-staging
kubernetes.io/ingress.class=nginx

Refs

https://cert-manager.io/docs/configuration/acme/