Aller au contenu

Enable HTTPS with Let's Encrypt

Brouillon : cette page n'a pas encore été relue et peut être incomplète ou inexacte.

This guide explains how to enable HTTPS for your Kubernetes deployment using cert-manager and Let’s Encrypt.

  • cert-manager: Automatically manages SSL/TLS certificates
  • Let’s Encrypt: Free, automated certificate authority
  • Nginx Ingress Controller: Routes HTTP/HTTPS traffic to services
  • Ingress: Kubernetes resource that manages external access
  • Kubernetes cluster (Digital Ocean, GKE, EKS, etc.)
  • Domain names pointing to your cluster
  • kubectl configured
Fenêtre de terminal
# Install cert-manager v1.13.3
kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.13.3/cert-manager.yaml
# Wait for cert-manager to be ready
kubectl wait --for=condition=available --timeout=300s \
deployment/cert-manager -n cert-manager
kubectl wait --for=condition=available --timeout=300s \
deployment/cert-manager-webhook -n cert-manager
# Verify installation
kubectl get pods -n cert-manager

Create letsencrypt-issuer.yaml:

apiVersion: cert-manager.io/v1
kind: ClusterIssuer
metadata:
name: letsencrypt-prod
spec:
acme:
server: https://acme-v02.api.letsencrypt.org/directory
email: your-email@example.com # ⚠️ CHANGE THIS!
privateKeySecretRef:
name: letsencrypt-prod
solvers:
- http01:
ingress:
class: nginx
---
apiVersion: cert-manager.io/v1
kind: ClusterIssuer
metadata:
name: letsencrypt-staging
spec:
acme:
server: https://acme-staging-v02.api.letsencrypt.org/directory
email: your-email@example.com # ⚠️ CHANGE THIS!
privateKeySecretRef:
name: letsencrypt-staging
solvers:
- http01:
ingress:
class: nginx

Apply the issuers:

Fenêtre de terminal
kubectl apply -f letsencrypt-issuer.yaml
# Verify issuers are ready
kubectl get clusterissuer

Note: Use letsencrypt-staging for testing, then switch to letsencrypt-prod for production.

Fenêtre de terminal
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.9.5/deploy/static/provider/do/deploy.yaml
# Wait for ingress controller to be ready
kubectl wait --namespace ingress-nginx \
--for=condition=ready pod \
--selector=app.kubernetes.io/component=controller \
--timeout=300s
# Get the LoadBalancer IP
kubectl get service -n ingress-nginx ingress-nginx-controller
  • AWS: Use deploy/static/provider/aws/deploy.yaml
  • GCP: Use deploy/static/provider/cloud/deploy.yaml
  • Azure: Use deploy/static/provider/cloud/deploy.yaml

Update your DNS A records to point to the Ingress LoadBalancer IP:

Type Name Value
A dev.kilimmanjaro.com <INGRESS_IP>
A api.dev.kilimmanjaro.com <INGRESS_IP>

Example (if Ingress IP is x.x.x.x):

A dev.kilimmanjaro.com x.x.x.x
A api.dev.kilimmanjaro.com x.x.x.x

Wait for DNS propagation (can take 5-60 minutes):

Fenêtre de terminal
# Check DNS propagation
nslookup dev.kilimmanjaro.com
nslookup api.dev.kilimmanjaro.com

Since we’re using Ingress, services no longer need LoadBalancers:

Fenêtre de terminal
# Update backend service
kubectl patch service api-gateway -p '{"spec":{"type":"ClusterIP"}}'
# Update frontend service
kubectl patch service kilimmanjaro-frontend -p '{"spec":{"type":"ClusterIP"}}'

Create ingress-https.yaml:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: kilimmanjaro-ingress
annotations:
cert-manager.io/cluster-issuer: "letsencrypt-prod" # Use staging for testing
nginx.ingress.kubernetes.io/ssl-redirect: "true"
spec:
ingressClassName: nginx
tls:
- hosts:
- dev.kilimmanjaro.com
- api.dev.kilimmanjaro.com
secretName: kilimmanjaro-tls # Certificate will be stored here
rules:
- host: dev.kilimmanjaro.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: kilimmanjaro-frontend
port:
number: 80
- host: api.dev.kilimmanjaro.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: api-gateway
port:
number: 80

Apply the ingress:

Fenêtre de terminal
kubectl apply -f ingress-https.yaml
Fenêtre de terminal
# Check certificate status
kubectl get certificate
# Watch certificate events
kubectl describe certificate kilimmanjaro-tls
# View certificate request
kubectl get certificaterequest
# Check cert-manager logs if needed
kubectl logs -n cert-manager deployment/cert-manager -f

Certificate status will change from False to True when ready (usually 1-2 minutes).

Once the certificate is issued:

Fenêtre de terminal
# Test HTTPS
curl -I https://dev.kilimmanjaro.com
curl -I https://api.dev.kilimmanjaro.com/api/health
# Check certificate details
openssl s_client -connect dev.kilimmanjaro.com:443 -servername dev.kilimmanjaro.com < /dev/null 2>/dev/null | openssl x509 -noout -dates

Visit in browser:

Fenêtre de terminal
# Check certificate request details
kubectl describe certificaterequest
# Check challenges
kubectl get challenges
kubectl describe challenge <challenge-name>
# Verify DNS is pointing to Ingress
kubectl get ingress
nslookup dev.kilimmanjaro.com

Common issues:

  • DNS not pointing to Ingress IP
  • Firewall blocking port 80
  • Service not responding
Fenêtre de terminal
# Test HTTP endpoint (cert challenge)
curl http://dev.kilimmanjaro.com/.well-known/acme-challenge/test
Fenêtre de terminal
# Check ingress configuration
kubectl describe ingress kilimmanjaro-ingress
# Verify TLS secret exists
kubectl get secret kilimmanjaro-tls
kubectl describe secret kilimmanjaro-tls
# Check ingress logs
kubectl logs -n ingress-nginx deployment/ingress-nginx-controller

Let’s Encrypt has rate limits:

  • Staging: No limits (use for testing)
  • Production: 5 certificates per week per domain

If you hit rate limits, use staging issuer:

annotations:
cert-manager.io/cluster-issuer: "letsencrypt-staging" # Use this first!

Update your API Gateway to allow HTTPS origins:

apps/kilimmandjaro-api-gateway/src/main.ts
app.enableCors({
origin: [
'http://localhost:3000',
'https://dev.kilimmanjaro.com', // Add HTTPS
'https://test.kilimmanjaro.com', // Add HTTPS
'https://kilimmanjaro.com', // Add HTTPS
],
credentials: true,
methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'],
allowedHeaders: ['Content-Type', 'Authorization'],
});

Rebuild and redeploy the API Gateway.

Certificates auto-renew 30 days before expiration. Monitor renewals:

Fenêtre de terminal
# Check certificate expiry
kubectl get certificate kilimmanjaro-tls -o jsonpath='{.status.notAfter}'
# Force renewal (if needed)
kubectl delete secret kilimmanjaro-tls

Common annotations for production:

metadata:
annotations:
# SSL
cert-manager.io/cluster-issuer: "letsencrypt-prod"
nginx.ingress.kubernetes.io/ssl-redirect: "true"
nginx.ingress.kubernetes.io/force-ssl-redirect: "true"
# Security
nginx.ingress.kubernetes.io/enable-cors: "true"
nginx.ingress.kubernetes.io/cors-allow-methods: "GET, POST, PUT, DELETE, OPTIONS"
nginx.ingress.kubernetes.io/cors-allow-credentials: "true"
# Performance
nginx.ingress.kubernetes.io/proxy-body-size: "10m"
nginx.ingress.kubernetes.io/proxy-connect-timeout: "600"
nginx.ingress.kubernetes.io/proxy-send-timeout: "600"
nginx.ingress.kubernetes.io/proxy-read-timeout: "600"
# Rate limiting
nginx.ingress.kubernetes.io/limit-rps: "100"
  1. ✅ Install cert-manager
  2. ✅ Create Let’s Encrypt ClusterIssuers
  3. ✅ Install Nginx Ingress Controller
  4. ⚠️ Update DNS to point to Ingress IP
  5. ✅ Convert services to ClusterIP
  6. ✅ Create Ingress with TLS
  7. ⏳ Wait for certificate issuance (1-2 minutes)
  8. ✅ Test HTTPS
  • Monitor certificate expiry
  • Setup alerts for certificate renewal failures
  • Consider adding rate limiting
  • Setup monitoring for Ingress
  • Configure additional security headers