Digital Ocean Kubernetes Deployment Guide
Brouillon : cette page n'a pas encore été relue et peut être incomplète ou inexacte.
This guide walks you through deploying the Kili Shops microservices (backend) and Kilimmanjaro frontend to a Digital Ocean Kubernetes cluster for testing.
Table of Contents
Section intitulée « Table of Contents »- Prerequisites
- Step 1: Create Digital Ocean Kubernetes Cluster
- Step 2: Configure kubectl
- Step 3: Setup Container Registry
- Step 4: Build and Push Docker Images
- Step 5: Deploy Backend Services
- Step 6: Deploy Frontend
- Step 7: Configure DNS and Access
- Step 8: Testing and Verification
- Troubleshooting
- Cleanup
Prerequisites
Section intitulée « Prerequisites »Required Tools
Section intitulée « Required Tools »-
Digital Ocean Account
- Sign up at https://www.digitalocean.com
- Add payment method
-
doctl CLI (Digital Ocean CLI)
Fenêtre de terminal # macOSbrew install doctl# Linuxcd ~wget https://github.com/digitalocean/doctl/releases/download/v1.94.0/doctl-1.94.0-linux-amd64.tar.gztar xf ~/doctl-1.94.0-linux-amd64.tar.gzsudo mv ~/doctl /usr/local/bin# Verifydoctl version -
kubectl
Fenêtre de terminal # Already installed from previous setupkubectl version --client -
Helm
Fenêtre de terminal # Already installed from previous setuphelm version -
Docker
Fenêtre de terminal # Verify Docker is runningdocker --version
Authenticate doctl
Section intitulée « Authenticate doctl »# Get API token from Digital Ocean# Go to: https://cloud.digitalocean.com/account/api/tokens# Create a new token with read/write access
# Authenticatedoctl auth init
# Paste your API token when prompted
# Verify authenticationdoctl account getStep 1: Create Digital Ocean Kubernetes Cluster
Section intitulée « Step 1: Create Digital Ocean Kubernetes Cluster »Option A: Using the Digital Ocean Web Interface
Section intitulée « Option A: Using the Digital Ocean Web Interface »-
Go to Digital Ocean Dashboard
-
Create Cluster
- Click “Create Kubernetes Cluster”
- Name:
kili-shops-test - Region: Choose closest to you (e.g.,
nyc1,sfo3,sgp1) - Kubernetes Version: Latest stable version (e.g.,
1.28.x) - Node Pool:
- Plan: Basic nodes
- Machine Type:
2 vCPU / 4 GB RAM($24/month per node) - Node Count: 3 nodes (for high availability)
- Total Monthly Cost: ~$72
-
Create Cluster
- Click “Create Cluster”
- Wait 3-5 minutes for cluster to provision
Option B: Using doctl CLI
Section intitulée « Option B: Using doctl CLI »# Create cluster with 3 nodesdoctl kubernetes cluster create kili-shops-test \ --region nyc1 \ --version 1.28.2-do.0 \ --node-pool "name=worker-pool;size=s-2vcpu-4gb;count=3" \ --wait
# This will take 3-5 minutesVerify Cluster Creation
Section intitulée « Verify Cluster Creation »# List clustersdoctl kubernetes cluster list
# Output example:# ID Name Region Version Auto Upgrade Status Node Pools# abc123 kili-shops-test nyc1 1.28.2-do.0 false running worker-poolStep 2: Configure kubectl
Section intitulée « Step 2: Configure kubectl »Download Cluster Config
Section intitulée « Download Cluster Config »# Download kubeconfigdoctl kubernetes cluster kubeconfig save kili-shops-test
# This adds the cluster to your ~/.kube/config
# Verify connectionkubectl cluster-info
# Check nodeskubectl get nodes
# Expected output: 3 nodes in Ready stateSet Context (if you have multiple clusters)
Section intitulée « Set Context (if you have multiple clusters) »# List contextskubectl config get-contexts
# Switch to Digital Ocean clusterkubectl config use-context do-nyc1-kili-shops-test
# Verifykubectl config current-contextStep 3: Setup Container Registry
Section intitulée « Step 3: Setup Container Registry »You have two options for storing Docker images:
Option A: Digital Ocean Container Registry (Recommended)
Section intitulée « Option A: Digital Ocean Container Registry (Recommended) »# Create registrydoctl registry create kili-shops
# Login to registrydoctl registry login
# Get registry URLdoctl registry get# Example: registry.digitalocean.com/kili-shopsOption B: Docker Hub (Free)
Section intitulée « Option B: Docker Hub (Free) »# Login to Docker Hubdocker login
# You'll use docker.io/YOUR_USERNAME/image-nameFor this guide, we’ll use Digital Ocean Container Registry.
Configure Kubernetes to Pull from Registry
Section intitulée « Configure Kubernetes to Pull from Registry »Digital Ocean automatically creates an image pull secret, but verify:
# Check for registry secretkubectl get secret -n kube-system | grep registry
# If using DO registry, it should be automatically configuredStep 4: Build and Push Docker Images
Section intitulée « Step 4: Build and Push Docker Images »4.1: Backend Images
Section intitulée « 4.1: Backend Images »# Navigate to backend projectcd /Users/moise/projects/af-corp/kili-shops-microservices
# Set registry URL (replace with your registry)REGISTRY="registry.digitalocean.com/kili-shops"
# Build and tag imagesecho "Building API Gateway..."docker build -f Dockerfile.gateway -t ${REGISTRY}/api-gateway:v1.0.0 .docker tag ${REGISTRY}/api-gateway:v1.0.0 ${REGISTRY}/api-gateway:latest
echo "Building Shops service..."docker build -f Dockerfile.shops -t ${REGISTRY}/shops:v1.0.0 .docker tag ${REGISTRY}/shops:v1.0.0 ${REGISTRY}/shops:latest
echo "Building Users service..."docker build -f Dockerfile.users -t ${REGISTRY}/users:v1.0.0 .docker tag ${REGISTRY}/users:v1.0.0 ${REGISTRY}/users:latest
# Push images to registryecho "Pushing images..."docker push ${REGISTRY}/api-gateway:v1.0.0docker push ${REGISTRY}/api-gateway:latestdocker push ${REGISTRY}/shops:v1.0.0docker push ${REGISTRY}/shops:latestdocker push ${REGISTRY}/users:v1.0.0docker push ${REGISTRY}/users:latest
# Verify imagesdoctl registry repository list-v24.2: Frontend Image
Section intitulée « 4.2: Frontend Image »# Navigate to frontend projectcd /Users/moise/projects/af-corp/kilimmanjaro
# Get the LoadBalancer IP or domain for backend API# (We'll come back to this after deploying backend)
# For now, use a placeholder - we'll rebuild after backend is deployedREGISTRY="registry.digitalocean.com/kili-shops"
# Build frontend (placeholder API URL)docker build \ --build-arg REACT_APP_API_URL="http://BACKEND_URL_HERE/api" \ -t ${REGISTRY}/frontend:v1.0.0 \ -f Dockerfile .
docker tag ${REGISTRY}/frontend:v1.0.0 ${REGISTRY}/frontend:latest
# Push to registrydocker push ${REGISTRY}/frontend:v1.0.0docker push ${REGISTRY}/frontend:latestStep 5: Deploy Backend Services
Section intitulée « Step 5: Deploy Backend Services »5.1: Create Production Values File
Section intitulée « 5.1: Create Production Values File »cd /Users/moise/projects/af-corp/kili-shops-microservices
# Create production valuescat > helm/kili-shops/values-do.yaml << 'EOF'# Digital Ocean production values
# Use registry imagesglobal: imagePullPolicy: Always
apiGateway: enabled: true replicaCount: 2 image: repository: registry.digitalocean.com/afcorp/api-gateway tag: latest service: type: LoadBalancer # DO will create a Load Balancer port: 80 resources: limits: cpu: 500m memory: 512Mi requests: cpu: 250m memory: 256Mi
shops: enabled: true replicaCount: 2 image: repository: registry.digitalocean.com/afcorp/shops tag: latest resources: limits: cpu: 500m memory: 512Mi requests: cpu: 250m memory: 256Mi
users: enabled: true replicaCount: 2 image: repository: registry.digitalocean.com/afcorp/users tag: latest resources: limits: cpu: 500m memory: 512Mi requests: cpu: 250m memory: 256Mi
mongodb: enabled: true persistence: enabled: true size: 10Gi storageClass: "do-block-storage" resources: limits: cpu: 1000m memory: 1Gi requests: cpu: 500m memory: 512Mi
postgresql: enabled: true persistence: enabled: true size: 10Gi storageClass: "do-block-storage" env: POSTGRES_PASSWORD: "CHANGE_ME_IN_PRODUCTION" # Change this! resources: limits: cpu: 1000m memory: 1Gi requests: cpu: 500m memory: 512MiEOF
echo "✓ Created values-do.yaml"echo "⚠️ IMPORTANT: Edit values-do.yaml and change the PostgreSQL password!"5.2: Deploy Backend with Helm
Section intitulée « 5.2: Deploy Backend with Helm »# Install backendhelm install kili-shops ./helm/kili-shops -f ./helm/kili-shops/values-do.yaml
# Watch deploymentkubectl get pods -w
# Wait for all pods to be Running (this may take 5-10 minutes)# Press Ctrl+C when done watching5.3: Get Load Balancer IP
Section intitulée « 5.3: Get Load Balancer IP »# Wait for Load Balancer to be provisioned (2-3 minutes)kubectl get service api-gateway -w
# When EXTERNAL-IP shows an IP address (not <pending>), press Ctrl+C
# Get the IPexport BACKEND_IP=$(kubectl get service api-gateway -o jsonpath='{.status.loadBalancer.ingress[0].ip}')echo "Backend API available at: http://${BACKEND_IP}"
# Test the backendcurl http://${BACKEND_IP}/healthStep 6: Deploy Frontend
Section intitulée « Step 6: Deploy Frontend »6.1: Rebuild Frontend with Real Backend URL
Section intitulée « 6.1: Rebuild Frontend with Real Backend URL »cd /Users/moise/projects/af-corp/kilimmanjaro
# Use the backend IP from previous stepREGISTRY="registry.digitalocean.com/kili-shops"BACKEND_IP="YOUR_BACKEND_IP_HERE" # Replace with actual IP
# Rebuild frontend with correct API URLdocker build \ --build-arg REACT_APP_API_URL="http://${BACKEND_IP}/api" \ -t ${REGISTRY}/frontend:v1.0.0 \ -f Dockerfile .
docker tag ${REGISTRY}/frontend:v1.0.0 ${REGISTRY}/frontend:latest
# Push updated imagedocker push ${REGISTRY}/frontend:v1.0.0docker push ${REGISTRY}/frontend:latest6.2: Create Frontend Production Values
Section intitulée « 6.2: Create Frontend Production Values »cat > helm/kilimmanjaro-frontend/values-do.yaml << EOF# Digital Ocean production values for frontend
frontend: enabled: true replicaCount: 2
image: repository: registry.digitalocean.com/afcorp/frontend tag: latest pullPolicy: Always
service: type: LoadBalancer port: 80
env: REACT_APP_API_URL: "http://${BACKEND_IP}/api"
resources: limits: cpu: 200m memory: 256Mi requests: cpu: 100m memory: 128MiEOF
echo "✓ Created frontend values-do.yaml"6.3: Deploy Frontend
Section intitulée « 6.3: Deploy Frontend »# Install frontendhelm install kilimmanjaro ./helm/kilimmanjaro-frontend -f ./helm/kilimmanjaro-frontend/values-do.yaml
# Watch deploymentkubectl get pods -l app.kubernetes.io/component=frontend -w
# Get frontend Load Balancer IP (wait 2-3 minutes)kubectl get service kilimmanjaro-frontend -w
# When EXTERNAL-IP appears, press Ctrl+C
# Get the IPexport FRONTEND_IP=$(kubectl get service kilimmanjaro-frontend -o jsonpath='{.status.loadBalancer.ingress[0].ip}')echo "Frontend available at: http://${FRONTEND_IP}"Step 7: Configure DNS and Access
Section intitulée « Step 7: Configure DNS and Access »Option A: Use IP Addresses Directly (Testing)
Section intitulée « Option A: Use IP Addresses Directly (Testing) »echo "Backend API: http://${BACKEND_IP}"echo "Frontend: http://${FRONTEND_IP}"
# Open in browseropen "http://${FRONTEND_IP}"Option B: Configure DNS (Recommended)
Section intitulée « Option B: Configure DNS (Recommended) »-
Go to your DNS provider (Namecheap, GoDaddy, Cloudflare, etc.)
-
Add A records:
Type Name ValueA api.test.kilimmanjaro [BACKEND_IP]A test.kilimmanjaro [FRONTEND_IP] -
Wait for DNS propagation (5-30 minutes)
-
Update frontend to use domain:
Fenêtre de terminal cd /Users/moise/projects/af-corp/kilimmanjaro# Rebuild with domaindocker build \--build-arg REACT_APP_API_URL="http://api.dev.kilimmanjaro.com/api" \-t registry.digitalocean.com/afcorp/frontend:v1.0.0 \-f Dockerfile .docker push registry.digitalocean.com/afcorp/frontend:v1.0.0# Restart frontend pods to pull new imagekubectl rollout restart deployment/kilimmanjaro-frontend -
Access:
- Frontend:
http://dev.kilimmanjaro.com - Backend API:
http://api.dev.kilimmanjaro.com
- Frontend:
Step 8: Testing and Verification
Section intitulée « Step 8: Testing and Verification »8.1: Check All Pods
Section intitulée « 8.1: Check All Pods »# Check all podskubectl get pods
# All pods should be in Running state# Expected pods:# - api-gateway-xxx (2 replicas)# - shops-xxx (2 replicas)# - users-xxx (2 replicas)# - mongodb-0 (1 StatefulSet)# - postgres-0 (1 StatefulSet)# - kilimmanjaro-frontend-xxx (2 replicas)8.2: Check Services
Section intitulée « 8.2: Check Services »# Check all serviceskubectl get services
# Should see:# - api-gateway (LoadBalancer with EXTERNAL-IP)# - kilimmanjaro-frontend (LoadBalancer with EXTERNAL-IP)# - mongodb, postgres, shops, users (ClusterIP)8.3: Test Backend API
Section intitulée « 8.3: Test Backend API »# Health checkcurl http://${BACKEND_IP}/health
# Get shops (should return empty array initially)curl http://${BACKEND_IP}/api/shops
# Get users (should return empty array initially)curl http://${BACKEND_IP}/api/users
# Create a test shopcurl -X POST http://${BACKEND_IP}/api/shops \ -H "Content-Type: application/json" \ -d '{ "name": "Test Shop", "description": "A test shop", "location": "New York" }'
# Verify shop was createdcurl http://${BACKEND_IP}/api/shops8.4: Test Frontend
Section intitulée « 8.4: Test Frontend »# Open in browserecho "Open: http://${FRONTEND_IP}"
# Or if using DNSecho "Open: http://dev.kilimmanjaro.com"In the browser:
- Navigate to the frontend URL
- Check that pages load correctly
- Try creating a shop or user
- Verify data persists
8.5: Check Logs
Section intitulée « 8.5: Check Logs »# API Gateway logskubectl logs -f deployment/api-gateway
# Shops service logskubectl logs -f deployment/shops
# Users service logskubectl logs -f deployment/users
# Frontend logskubectl logs -f deployment/kilimmanjaro-frontend
# Database logskubectl logs -f statefulset/mongodbkubectl logs -f statefulset/postgres8.6: Check Resource Usage
Section intitulée « 8.6: Check Resource Usage »# Install metrics server (if not already installed)kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml
# Wait a minute, then checkkubectl top nodeskubectl top podsTroubleshooting
Section intitulée « Troubleshooting »Pods Not Starting
Section intitulée « Pods Not Starting »# Describe pod to see eventskubectl describe pod <pod-name>
# Check logskubectl logs <pod-name>
# Check if image existsdoctl registry repository list-tags <repository-name>ImagePullBackOff Error
Section intitulée « ImagePullBackOff Error »# Verify registry authenticationkubectl get secret -n kube-system | grep registry
# Re-authenticate with registrydoctl registry login
# If using DO registry, ensure cluster has accessdoctl registry kubernetes-manifest | kubectl apply -f -Load Balancer Stuck in Pending
Section intitulée « Load Balancer Stuck in Pending »# Check servicekubectl describe service api-gateway
# Digital Ocean may have limits - check dashboard# Ensure you have fewer than the account limit of Load BalancersDatabase Connection Issues
Section intitulée « Database Connection Issues »# Check database podskubectl get pods -l app.kubernetes.io/component=database
# Check logskubectl logs statefulset/mongodbkubectl logs statefulset/postgres
# Test connectivity from app podkubectl exec -it deployment/shops -- nc -zv mongodb 27017kubectl exec -it deployment/users -- nc -zv postgres 5432Frontend Can’t Reach Backend
Section intitulée « Frontend Can’t Reach Backend »This is usually because the API URL is wrong:
# Check what API URL was baked into frontendkubectl get configmap kilimmanjaro-frontend-config -o yaml
# If wrong, rebuild frontend with correct URL and redeployMonitoring and Maintenance
Section intitulée « Monitoring and Maintenance »View Cluster Resources
Section intitulée « View Cluster Resources »# Digital Ocean dashboardecho "View cluster at: https://cloud.digitalocean.com/kubernetes/clusters"
# Or via CLIdoctl kubernetes cluster get kili-shops-testUpdate Application
Section intitulée « Update Application »# Backend updatecd /Users/moise/projects/af-corp/kili-shops-microservices
# Build and push new versiondocker build -f Dockerfile.gateway -t registry.digitalocean.com/afcorp/api-gateway:v1.1.0 .docker push registry.digitalocean.com/afcorp/api-gateway:v1.1.0
# Update Helm values to use new tag# Then upgradehelm upgrade kili-shops ./helm/kili-shops -f ./helm/kili-shops/values-do.yaml
# Frontend updatecd /Users/moise/projects/af-corp/kilimmanjarodocker build --build-arg REACT_APP_API_URL="http://${BACKEND_IP}/api" \ -t registry.digitalocean.com/afcorp/frontend:v1.1.0 .docker push registry.digitalocean.com/afcorp/frontend:v1.1.0
helm upgrade kilimmanjaro ./helm/kilimmanjaro-frontend -f ./helm/kilimmanjaro-frontend/values-do.yaml# Scale API Gatewaykubectl scale deployment api-gateway --replicas=3
# Or update Helm values and upgradeDelete Applications
Section intitulée « Delete Applications »# Uninstall frontendhelm uninstall kilimmanjaro
# Uninstall backendhelm uninstall kili-shops
# Delete PVCs (this deletes database data!)kubectl delete pvc --allDelete Cluster
Section intitulée « Delete Cluster »# Via CLIdoctl kubernetes cluster delete kili-shops-test
# Or via web interface# Go to: https://cloud.digitalocean.com/kubernetes/clusters# Click on cluster → Settings → DestroyDelete Container Registry
Section intitulée « Delete Container Registry »# Delete registrydoctl registry delete kili-shops
# This deletes all imagesCost Estimation
Section intitulée « Cost Estimation »Monthly costs for this setup:
- Kubernetes Cluster: 3 nodes × $24/month = $72/month
- Load Balancers: 2 × $12/month = $24/month
- Block Storage (PVCs): 20GB × $0.10/GB = $2/month
- Container Registry: Free tier (500MB storage)
Total: ~$98/month
To reduce costs:
- Use 2 nodes instead of 3: ~$50/month savings
- Use NodePort instead of LoadBalancer for frontend: $12/month savings
- Use smaller nodes ($18/month each): ~$18/month savings
Security Recommendations
Section intitulée « Security Recommendations »For Production Deployment:
Section intitulée « For Production Deployment: »-
Change PostgreSQL Password
Fenêtre de terminal # Generate strong passwordopenssl rand -base64 32# Update in values-do.yaml# Then upgrade: helm upgrade kili-shops ... -
Enable HTTPS
- Use cert-manager for automatic SSL certificates
- Configure ingress with TLS
-
Setup Ingress Controller
- Instead of LoadBalancer per service
- One LoadBalancer with ingress routing
-
Enable Network Policies
- Restrict pod-to-pod communication
-
Setup Monitoring
- Prometheus + Grafana
- Digital Ocean Monitoring
-
Setup Backups
- Database backups
- Automated snapshots
Next Steps
Section intitulée « Next Steps »After successful deployment:
-
Setup CI/CD
- GitHub Actions to auto-deploy on push
- Automated testing
-
Setup Monitoring
- Application monitoring
- Error tracking (Sentry)
-
Setup Logging
- Centralized logging (ELK stack)
-
Performance Optimization
- Enable caching
- Optimize database queries
- CDN for frontend assets
-
Security Hardening
- Regular security updates
- Vulnerability scanning
- Secret management (Sealed Secrets or Vault)
Support and Resources
Section intitulée « Support and Resources »- Digital Ocean Docs: https://docs.digitalocean.com/products/kubernetes/
- Kubernetes Docs: https://kubernetes.io/docs/
- Helm Docs: https://helm.sh/docs/
- Project README: See KUBERNETES.md for detailed K8s documentation