Skip to content

Let's Encrypt Certificate Setup Manual for Kubernetes Clusters

This manual explains how to set up Let's Encrypt certificates for Kubernetes clusters. We provide a structured environment where you can obtain and manage certificates. Follow the instructions to configure staging certificates first for testing, and then move on to the production phase.

Step 1: Setting up Let's Encrypt Staging Certificates

We start by setting up staging certificates to ensure that all configurations are correct without risking hitting Let's Encrypt's rate limits. Staging certificates are not browser-trusted but allow you to verify your setup.

1.1 Configure the Staging Issuer

In /opt/k8s-template-v2/02_LETSENCRYPT/10_certificate_management/01_letsencrypt-stageing.yml, we define the issuer for Let's Encrypt’s staging environment. This issuer will request certificates from the Let's Encrypt staging server.

kubectl apply -f /opt/k8s-template-v2/02_LETSENCRYPT/10_certificate_management/01_letsencrypt-stageing.yml

Make sure to update the email field with your email address before applying the YAML file. This is needed for notifications from Let's Encrypt.

1.2 Request a Staging Certificate

After setting up the issuer, we will create a staging certificate using the file 03_create-certificate-staging.yml. This will request a certificate for the specified domains in the staging environment.

kubectl apply -f /opt/k8s-template-v2/02_LETSENCRYPT/10_certificate_management/03_create-certificate-staging.yml

Be sure to fill in the commonName and dnsNames with your domain names (e.g., nginx.*.init-lab.ch).

Step 2: Deploying Staging Workloads

To verify that the certificates work correctly, you need to apply the staging configurations for the test workloads (NGINX, WordPress, and X11). The YAML files for these workloads are found in /opt/k8s-template-v2/02_LETSENCRYPT/20_test_workloads/.

2.1 Deploy NGINX Staging Configuration

Apply the following YAML file to set up an NGINX deployment and secure it using the staging certificate.

kubectl apply -f /opt/k8s-template-v2/02_LETSENCRYPT/20_test_workloads/02_nginx/02_nginx-https-ingress-staging.yaml

2.2 Deploy WordPress Staging Configuration

Similarly, deploy the WordPress workload with the staging certificate.

kubectl apply -f /opt/k8s-template-v2/02_LETSENCRYPT/20_test_workloads/03_wordpress/02_wordpress-https-ingress-staging.yml

2.3 Deploy X11 Staging Configuration

Finally, deploy the X11 workload using the staging certificate.

kubectl apply -f /opt/k8s-template-v2/02_LETSENCRYPT/20_test_workloads/04_x11/02_x11-https-ingress-staging.yml

Step 3: Configuring HTTP to HTTPS Redirection

To ensure that all HTTP traffic is automatically redirected to HTTPS, we will configure middleware and Ingress rules.

3.1 Apply the Middleware for HTTPS Redirection

The middleware configuration is defined in the file 01_middleware.yaml. Apply it to the cluster:

kubectl apply -f /opt/k8s-template-v2/02_LETSENCRYPT/30_http-https-redirect/01_middleware.yaml

3.2 Apply the Redirect Configuration

Now, set up the HTTP to HTTPS redirection for each service using 02_redirect.yaml.

kubectl apply -f /opt/k8s-template-v2/02_LETSENCRYPT/30_http-https-redirect/02_redirect.yaml

Step 4: Setting up Let's Encrypt Production Certificates

After completing the staging phase and confirming that everything works correctly, you can move on to the production phase. This will issue browser-trusted certificates for your services.

4.1 Configure the Production Issuer

Apply the production issuer configuration using the file 02_letsencrypt-production.yml.

kubectl apply -f /opt/k8s-template-v2/02_LETSENCRYPT/10_certificate_management/02_letsencrypt-production.yml

4.2 Request a Production Certificate

After configuring the production issuer, create the production certificate using the file 04_create-certificate-production.yml.

kubectl apply -f /opt/k8s-template-v2/02_LETSENCRYPT/10_certificate_management/04_create-certificate-production.yml

4.3 Deploy Production Workloads

Now apply the production configurations for each workload.

NGINX Production:

kubectl apply -f /opt/k8s-template-v2/02_LETSENCRYPT/20_test_workloads/02_nginx/03_nginx-https-ingress.yaml

WordPress Production:

kubectl apply -f /opt/k8s-template-v2/02_LETSENCRYPT/20_test_workloads/03_wordpress/03_wordpress-https-ingress.yml

X11 Production:

kubectl apply -f /opt/k8s-template-v2/02_LETSENCRYPT/20_test_workloads/04_x11/03_x11-https-ingress.yml

Conclusion

Following these steps will ensure that you properly set up Let's Encrypt certificates for your Kubernetes workloads. Start with the staging phase to test the configuration, and once verified, proceed to the production phase for valid browser-trusted certificates.