This is my post install on a fresh k3s kubernetes cluster on Hetzner cloud.
I used the excellent Kube-Hetzner terraform setup for
Hetzner Cloud and performed the following post config to setup TLS and deploy a secure WHOAMI sample application.
There are four main alternatives to issue certificates on kubernetes with Traefik
Proxy.
-
Cloud provider's load balancer - may have support to manage certificates.
This option is not standard, will vary between cloud providers with proprietary APIs. -
Traefik
--certificatesresolvers
declared in TraefikadditionalArguments:
configuration section.
This a popular approach where:- Certificates resolvers are declared only once per the cluster.
- Can be requested by an
Ingress
resource in theannotations:
section refering torouter.tls.certresolver
and certificate definitions intls.hosts
andtls.secretName
entries. - Can be requested by an
IngressRoute
resource without annotations. Everything goes in thetls
section, intls.certResolver
,tls.domains
andtls.options
attributes.
The downside:
- Won't work with multiple instances of Traefik (HA) as there is no way to ensure the correct instance receives the challenge request and subsequent responses.
- Certificate resolvers configurations are mixed with the static configuration of Traefik Proxy.
-
Cert-Manager with Ingress to manage certificates automatically. This is another popular solution that:
- Cert-Manager is not affected by Traefik HA.
- Separates certificate management configuration from Traefik Proxy configuration.
- Has full integration for
Ingress
resources sinceCert-Manager
"understands"Ingress
resources.Cert-Manager
will create temporary challenge response services being able to issue the certificate by theIngress
resource request.
The downside:
Cert-Mangager
does not integregate withIngressRoute
resources. There is a gap here,IngressRoute
integrates withTraefik
certificateresolvers
but not withCert-Manager
to auto issue certificates. Certificates must be requested either by anIngress
or by aCertificate
resource.
-
Cert-Manager with manual first issue that manages certificates renewal.
This is the approach I like best and is the one described in this document.- Cert-Manager is not affected by Traefik HA.
- Separates certificate management configuration from Traefik Proxy configuration.
- Compatible with
Ingress
resources without annotations (or optional annotation to use HTTPS only). - Compatible with
IngressRoute
. - Although certificate issue is manual it is therefore manually verified.
- Although certificate issue is manual, renewal is automatic.
The downside:
- First issue of a certificate is manual (but easy).
As mentioned above I do prefer to user Cert-Manager
and issue the certificate for HTTPS manually and
have the benefit of automatic renewal and use only IngressRoute
CRD rosources. This document will walk
you through the configurations necessary to use this approach.
This documentation requires that your DNS is already configured.
In the example we will also redirect www.domain URLs to their short domain equivalent. It is required that www and root addresses are both mapped in your DNS configuration, and it is OK to use the general *.domain CNAME for this.
On the other hand, when requesting a certificate with http challenge solvers every domain should be explicity defined (*.domain is only supported through dns challenge solvers).
Issuers is your CA representation. In this document we will be issuing LetsEncrypt certificates (staging and production), this the Issuer will be a service to interact with LetsEncrypt authority.
Cluster Issuers only differ from regular Issuer in the fact that they have no namespace and will be shared by IngressRoutes on all namespaces.
Instructions in Chapter 01-cluster-issuer.
Install the kute whoami webserver from Traefik dockerhub. This version may be configured to produce an ASCII message for the console.
This example installation goes step by step from issuing a letsencrypt staging certificate up to deploying the websecure application using Traefik CRD provider with production certificates and a set of middlewares for HTTP redirection, SSL strong security and 'www' prefix stripping.
Instructions in Chapter #2 - whoami.
This document is a compilation of best practices and instructions collected on the internet. Here I name some of the main resources I used to create this repository.
- APIs:
- Tutorials:
- Kube-Hetzner - Terraform template for Hetzner
- Workshop: Getting Started with Traefik - Traefik Labs tutorial with Jakub Hajek - Part #1
- Workshop: Advanced Load Balancing with Traefik 2.5 - Traefik Labs tutorial with Jakub Hajek - Part #2