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.
Overview
Section intitulée « Overview »- 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
Prerequisites
Section intitulée « Prerequisites »- Kubernetes cluster (Digital Ocean, GKE, EKS, etc.)
- Domain names pointing to your cluster
- kubectl configured
Step 1: Install cert-manager
Section intitulée « Step 1: Install cert-manager »# Install cert-manager v1.13.3kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.13.3/cert-manager.yaml
# Wait for cert-manager to be readykubectl wait --for=condition=available --timeout=300s \ deployment/cert-manager -n cert-managerkubectl wait --for=condition=available --timeout=300s \ deployment/cert-manager-webhook -n cert-manager
# Verify installationkubectl get pods -n cert-managerStep 2: Create Let’s Encrypt ClusterIssuers
Section intitulée « Step 2: Create Let’s Encrypt ClusterIssuers »Create letsencrypt-issuer.yaml:
apiVersion: cert-manager.io/v1kind: ClusterIssuermetadata: name: letsencrypt-prodspec: 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/v1kind: ClusterIssuermetadata: name: letsencrypt-stagingspec: 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: nginxApply the issuers:
kubectl apply -f letsencrypt-issuer.yaml
# Verify issuers are readykubectl get clusterissuerNote: Use letsencrypt-staging for testing, then switch to letsencrypt-prod for production.
Step 3: Install Nginx Ingress Controller
Section intitulée « Step 3: Install Nginx Ingress Controller »For Digital Ocean:
Section intitulée « For Digital Ocean: »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 readykubectl wait --namespace ingress-nginx \ --for=condition=ready pod \ --selector=app.kubernetes.io/component=controller \ --timeout=300s
# Get the LoadBalancer IPkubectl get service -n ingress-nginx ingress-nginx-controllerFor Other Providers:
Section intitulée « For Other Providers: »- AWS: Use
deploy/static/provider/aws/deploy.yaml - GCP: Use
deploy/static/provider/cloud/deploy.yaml - Azure: Use
deploy/static/provider/cloud/deploy.yaml
Step 4: Update DNS Records
Section intitulée « Step 4: Update DNS Records »Update your DNS A records to point to the Ingress LoadBalancer IP:
Type Name ValueA 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.xA api.dev.kilimmanjaro.com x.x.x.xWait for DNS propagation (can take 5-60 minutes):
# Check DNS propagationnslookup dev.kilimmanjaro.comnslookup api.dev.kilimmanjaro.comStep 5: Convert Services to ClusterIP
Section intitulée « Step 5: Convert Services to ClusterIP »Since we’re using Ingress, services no longer need LoadBalancers:
# Update backend servicekubectl patch service api-gateway -p '{"spec":{"type":"ClusterIP"}}'
# Update frontend servicekubectl patch service kilimmanjaro-frontend -p '{"spec":{"type":"ClusterIP"}}'Step 6: Create Ingress with TLS
Section intitulée « Step 6: Create Ingress with TLS »Create ingress-https.yaml:
apiVersion: networking.k8s.io/v1kind: Ingressmetadata: 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: 80Apply the ingress:
kubectl apply -f ingress-https.yamlStep 7: Monitor Certificate Issuance
Section intitulée « Step 7: Monitor Certificate Issuance »# Check certificate statuskubectl get certificate
# Watch certificate eventskubectl describe certificate kilimmanjaro-tls
# View certificate requestkubectl get certificaterequest
# Check cert-manager logs if neededkubectl logs -n cert-manager deployment/cert-manager -fCertificate status will change from False to True when ready (usually 1-2 minutes).
Step 8: Verify HTTPS
Section intitulée « Step 8: Verify HTTPS »Once the certificate is issued:
# Test HTTPScurl -I https://dev.kilimmanjaro.comcurl -I https://api.dev.kilimmanjaro.com/api/health
# Check certificate detailsopenssl s_client -connect dev.kilimmanjaro.com:443 -servername dev.kilimmanjaro.com < /dev/null 2>/dev/null | openssl x509 -noout -datesVisit in browser:
Troubleshooting
Section intitulée « Troubleshooting »Certificate Stuck in Pending
Section intitulée « Certificate Stuck in Pending »# Check certificate request detailskubectl describe certificaterequest
# Check challengeskubectl get challengeskubectl describe challenge <challenge-name>
# Verify DNS is pointing to Ingresskubectl get ingressnslookup dev.kilimmanjaro.comHTTP-01 Challenge Failed
Section intitulée « HTTP-01 Challenge Failed »Common issues:
- DNS not pointing to Ingress IP
- Firewall blocking port 80
- Service not responding
# Test HTTP endpoint (cert challenge)curl http://dev.kilimmanjaro.com/.well-known/acme-challenge/testCertificate Issued but HTTPS Not Working
Section intitulée « Certificate Issued but HTTPS Not Working »# Check ingress configurationkubectl describe ingress kilimmanjaro-ingress
# Verify TLS secret existskubectl get secret kilimmanjaro-tlskubectl describe secret kilimmanjaro-tls
# Check ingress logskubectl logs -n ingress-nginx deployment/ingress-nginx-controllerRate Limits
Section intitulée « Rate Limits »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!Updating CORS for HTTPS
Section intitulée « Updating CORS for HTTPS »Update your API Gateway to allow HTTPS origins:
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.
Certificate Renewal
Section intitulée « Certificate Renewal »Certificates auto-renew 30 days before expiration. Monitor renewals:
# Check certificate expirykubectl get certificate kilimmanjaro-tls -o jsonpath='{.status.notAfter}'
# Force renewal (if needed)kubectl delete secret kilimmanjaro-tlsAdditional Ingress Annotations
Section intitulée « Additional Ingress Annotations »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"- ✅ Install cert-manager
- ✅ Create Let’s Encrypt ClusterIssuers
- ✅ Install Nginx Ingress Controller
- ⚠️ Update DNS to point to Ingress IP
- ✅ Convert services to ClusterIP
- ✅ Create Ingress with TLS
- ⏳ Wait for certificate issuance (1-2 minutes)
- ✅ Test HTTPS
Next Steps
Section intitulée « Next Steps »- Monitor certificate expiry
- Setup alerts for certificate renewal failures
- Consider adding rate limiting
- Setup monitoring for Ingress
- Configure additional security headers