Visualization service - Setup K8s on Digital Ocean
Setting Up Kubernetes on DigitalOcean with HTTPS
This guide walks through setting up a production-ready Kubernetes cluster on DigitalOcean with automatic SSL certificate management using Let’s Encrypt.
Overview
We’ll set up:
- DigitalOcean Kubernetes cluster
- NGINX Ingress Controller
- cert-manager for automatic SSL certificates
- Domain configuration with HTTPS
- Test application to verify everything works
Prerequisites
- DigitalOcean account
- Domain name (I used my own domain
zeelu.mewith subdomainingresstest.do.zeelu.me) kubectlconfigured to access your clusterhelmpackage manager
Step 1: Create DigitalOcean Kubernetes Cluster
- Go to DigitalOcean Control Panel
- Navigate to Kubernetes → Create Cluster
- Choose your configuration:
- Datacenter: I used Toronto Datacenter
- Node pool: I only get 1 nodes for testing purpose, which I get vCPU: 1 Shared, vRAM: 2 GB, Storage: 50 GB for $12/month
- Node size: Basic plan (2GB RAM minimum) - The cheapest plan
- Click Create Cluster
Step 2: Configure kubectl
After the cluster is created, it will pop up some instructions, simply follow the DigitalOcean’s guide to install doctl, and set up the kubeconfig.
Step 3: Install Helm
Install Helm package manager:
1# On macOS with Homebrew2brew install helm34# Verify installation5helm versionAdd required repositories:
1helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx2helm repo add jetstack https://charts.jetstack.io3helm repo updateStep 4: Install NGINX Ingress Controller
Install the NGINX Ingress Controller:
1helm install ingress-nginx ingress-nginx/ingress-nginx \2 --namespace ingress-nginx \3 --create-namespaceCheck the installation:
1kubectl get pods --namespace ingress-nginx2kubectl get service --namespace ingress-nginx ingress-nginx-controller --output wideWait for the load balancer to get an external IP (usually 1-2 minutes).
Step 5: Configure DNS
- Go to DigitalOcean → Networking → Domains
- Find your domain (
zeelu.me) - Add an A record:
- Name:
ingresstest(foringresstest.do.zeelu.me) - Value:
YOUR_LOAD_BALANCER_IP(from step 4) - Normally you can select from the dropdown list - TTL: default
- Name:
Test DNS resolution:
Use nslookup or simply view the domain in the browser
1nslookup ingresstest.do.zeelu.meStep 6: Install cert-manager
Install cert-manager for automatic SSL certificate management:
1helm install cert-manager jetstack/cert-manager \2 --namespace cert-manager \3 --create-namespace \4 --set installCRDs=trueVerify installation:
1kubectl get pods --namespace cert-managerStep 7: Configure Let’s Encrypt Issuer
Create a ClusterIssuer for Let’s Encrypt:
1# letsencrypt-issuer.yaml2apiVersion: cert-manager.io/v13kind: ClusterIssuer4metadata:5 name: letsencrypt-prod6spec:7 acme:8 # The ACME server URL9 server: https://acme-v02.api.letsencrypt.org/directory10 # Email address used for ACME registration11 email: your-email@domain.com # Replace with your email12 # Name of a secret used to store the ACME account private key13 privateKeySecretRef:14 name: letsencrypt-prod15 # Enable the HTTP-01 challenge provider16 solvers:17 - http01:18 ingress:19 class: nginxApply the configuration:
1kubectl apply -f letsencrypt-issuer.yamlCheck the issuer status:
1kubectl get clusterissuer letsencrypt-prod2# Should show READY=TrueStep 8: Deploy Test Application
Create a simple test application:
1# Deploy nginx test app2kubectl create deployment test-app --image=nginx:alpine3kubectl expose deployment test-app --port=80 --type=ClusterIPStep 9: Configure HTTPS Ingress
Create an ingress with SSL certificate:
1# test-ingress.yaml2apiVersion: networking.k8s.io/v13kind: Ingress4metadata:5 name: test-ingress6 namespace: default7 annotations:8 cert-manager.io/cluster-issuer: "letsencrypt-prod"9spec:10 ingressClassName: nginx11 tls:12 - hosts:13 - ingresstest.do.zeelu.me14 secretName: ingresstest-tls15 rules:16 - host: ingresstest.do.zeelu.me17 http:18 paths:19 - path: /20 pathType: Prefix21 backend:22 service:23 name: test-app24 port:25 number: 80Apply the ingress:
1kubectl apply -f test-ingress.yamlStep 10: Verify SSL Certificate
Check certificate status:
1kubectl get certificates2kubectl describe certificate ingresstest-tlsWait for the certificate to be issued (usually 1-2 minutes). You should see READY=True.
Step 11: Test HTTPS
Test both HTTP and HTTPS:
1# Test HTTP2curl http://ingresstest.do.zeelu.me34# Test HTTPS5curl https://ingresstest.do.zeelu.me67# Test with headers8curl -I https://ingresstest.do.zeelu.meYou should see:
- HTTP/2 response
strict-transport-securityheader- Valid SSL certificate
Step 12: Browser Test
Visit https://ingresstest.do.zeelu.me in your browser. You should see the nginx welcome page.
Troubleshooting
DNS Issues
1# Check DNS resolution2nslookup ingresstest.do.zeelu.me3dig ingresstest.do.zeelu.me45# Test direct IP6curl -H "Host: ingresstest.do.zeelu.me" http://YOUR_LOAD_BALANCER_IPCertificate Issues
1# Check certificate status2kubectl get certificates3kubectl describe certificate ingresstest-tls45# Check challenges6kubectl get challenges7kubectl describe challenge CHALLENGE_NAME89# Check orders10kubectl get orders11kubectl describe order ORDER_NAMEIngress Issues
1# Check ingress status2kubectl get ingress3kubectl describe ingress test-ingress45# Check ingress controller logs6kubectl logs -n ingress-nginx deployment/ingress-nginx-controllerCleanup
To remove test resources:
1# Delete test application2kubectl delete deployment test-app3kubectl delete service test-app4kubectl delete ingress test-ingress5kubectl delete certificate ingresstest-tls67# Delete ingress controller (optional)8helm uninstall ingress-nginx --namespace ingress-nginx910# Delete cert-manager (optional)11helm uninstall cert-manager --namespace cert-managerResources
← Back to the journal