Kubernetes Deployment Guide - Kilimmanjaro Frontend
Brouillon : cette page n'a pas encore été relue et peut être incomplète ou inexacte.
This guide explains how to deploy the Kilimmanjaro React frontend to Kubernetes using Helm charts.
Table of Contents
Section intitulée « Table of Contents »- Prerequisites
- Quick Start
- Architecture
- Local Development
- Configuration
- Deployment
- Accessing the Application
- Monitoring and Troubleshooting
- Production Deployment
Prerequisites
Section intitulée « Prerequisites »Required Tools
Section intitulée « Required Tools »-
Kubernetes Cluster
- Docker Desktop with Kubernetes enabled, or
- Minikube, or
- Any cloud Kubernetes service (GKE, EKS, AKS)
-
Helm 3.0+
Fenêtre de terminal # Install Helm (macOS)brew install helm# Verify installationhelm version -
kubectl
Fenêtre de terminal # Install kubectl (macOS)brew install kubectl# Verify installationkubectl version --client -
Docker
Fenêtre de terminal # Verify Docker is installeddocker --version
Quick Start
Section intitulée « Quick Start »The fastest way to deploy to a local Kubernetes cluster:
# Make scripts executablechmod +x scripts/k8s-*.sh
# Deploy (builds image and deploys)./scripts/k8s-deploy.sh
# Access the frontend# - Docker Desktop: http://localhost:30080# - Minikube: Use URL from minikube service kilimmanjaro-frontend --urlTo clean up:
./scripts/k8s-cleanup.shArchitecture
Section intitulée « Architecture »The deployment consists of:
- Frontend Deployment - React app served by Nginx
- Service - LoadBalancer or NodePort for external access
- HorizontalPodAutoscaler - (Optional) Auto-scaling based on CPU
- Ingress - (Optional) For production domain routing
Docker Image
Section intitulée « Docker Image »The application uses a multi-stage Docker build:
- Build Stage - Compiles React app with Node.js
- Production Stage - Serves static files with Nginx
Key features:
- Optimized production build
- Gzip compression enabled
- Health check endpoint at
/health - React Router support (SPA routing)
- Security headers configured
Local Development
Section intitulée « Local Development »Docker Desktop
Section intitulée « Docker Desktop »-
Enable Kubernetes
- Open Docker Desktop → Settings → Kubernetes
- Check “Enable Kubernetes”
- Apply & Restart
-
Deploy Application
Fenêtre de terminal # Deploy with default settings./scripts/k8s-deploy.sh# Or manually./scripts/k8s-build-image.shhelm install kilimmanjaro ./helm/kilimmanjaro-frontend -f ./helm/kilimmanjaro-frontend/values-local.yaml -
Access Application
Fenêtre de terminal # Frontend available athttp://localhost:30080
Minikube
Section intitulée « Minikube »-
Start Minikube
Fenêtre de terminal # Start with sufficient resourcesminikube start --cpus=2 --memory=4096# Use Minikube's Docker daemoneval $(minikube docker-env) -
Deploy Application
Fenêtre de terminal ./scripts/k8s-deploy.sh -
Access Application
Fenêtre de terminal # Get service URLminikube service kilimmanjaro-frontend --url# Or use port forwardkubectl port-forward service/kilimmanjaro-frontend 8080:80
Configuration
Section intitulée « Configuration »Environment Variables
Section intitulée « Environment Variables »The main configuration is the API URL, which is baked into the build:
# values.yaml or values-local.yamlfrontend: env: REACT_APP_API_URL: "http://localhost:3000/api"Custom Configuration
Section intitulée « Custom Configuration »Create a custom values file:
frontend: replicaCount: 3
service: type: LoadBalancer port: 80
env: REACT_APP_API_URL: "https://api.kilimmanjaro.com/api"
resources: limits: cpu: 500m memory: 512Mi requests: cpu: 250m memory: 256Mi
autoscaling: enabled: true minReplicas: 2 maxReplicas: 10 targetCPUUtilizationPercentage: 70Deploy with custom values:
helm install kilimmanjaro ./helm/kilimmanjaro-frontend -f custom-values.yamlConnecting to Backend
Section intitulée « Connecting to Backend »Local Backend (Docker Desktop)
Section intitulée « Local Backend (Docker Desktop) »frontend: env: REACT_APP_API_URL: "http://localhost:3000/api"Local Backend (Minikube)
Section intitulée « Local Backend (Minikube) »# Get Minikube IPminikube ip # e.g., x.x.x.x
# Configure in values filefrontend: env: REACT_APP_API_URL: "http://x.x.x.x:30000/api"Backend in Kubernetes
Section intitulée « Backend in Kubernetes »If the backend is also in Kubernetes:
frontend: env: # Using Kubernetes service DNS REACT_APP_API_URL: "http://api-gateway.default.svc.cluster.local:3000/api"
# Or using Ingress REACT_APP_API_URL: "https://api.kilimmanjaro.com/api"Important: Since this is a React app, the API URL is baked into the JavaScript bundle at build time. To change the API URL, you must rebuild the image.
Deployment
Section intitulée « Deployment »Step-by-Step Deployment
Section intitulée « Step-by-Step Deployment »-
Build Docker Image
Fenêtre de terminal # Build with custom API URLREACT_APP_API_URL="http://localhost:3000/api" ./scripts/k8s-build-image.sh# Or just./scripts/k8s-build-image.sh # Uses default -
Install with Helm
Fenêtre de terminal # Installhelm install kilimmanjaro ./helm/kilimmanjaro-frontend -f ./helm/kilimmanjaro-frontend/values-local.yaml# Or upgrade if already installedhelm upgrade kilimmanjaro ./helm/kilimmanjaro-frontend -f ./helm/kilimmanjaro-frontend/values-local.yaml -
Verify Deployment
Fenêtre de terminal # Check podskubectl get pods -l app.kubernetes.io/component=frontend# Check servicekubectl get service kilimmanjaro-frontend# Check logskubectl logs -f deployment/kilimmanjaro-frontend
Updating the Deployment
Section intitulée « Updating the Deployment »# Method 1: Use deployment script./scripts/k8s-deploy.sh
# Method 2: Manual update./scripts/k8s-build-image.shhelm upgrade kilimmanjaro ./helm/kilimmanjaro-frontend
# Method 3: Rebuild with new API URLREACT_APP_API_URL="https://api.production.com/api" ./scripts/k8s-build-image.shhelm upgrade kilimmanjaro ./helm/kilimmanjaro-frontend \ --set frontend.env.REACT_APP_API_URL="https://api.production.com/api"
# Force pod restart to pick up new imagekubectl rollout restart deployment/kilimmanjaro-frontendAccessing the Application
Section intitulée « Accessing the Application »LoadBalancer (Docker Desktop)
Section intitulée « LoadBalancer (Docker Desktop) »# Get service detailskubectl get service kilimmanjaro-frontend
# Access directlyhttp://localhost:80NodePort (Minikube or Docker Desktop)
Section intitulée « NodePort (Minikube or Docker Desktop) »# Get node portkubectl get service kilimmanjaro-frontend
# Docker Desktophttp://localhost:30080
# Minikubeminikube service kilimmanjaro-frontend --urlPort Forwarding (Any Cluster)
Section intitulée « Port Forwarding (Any Cluster) »# Forward portkubectl port-forward service/kilimmanjaro-frontend 8080:80
# Access athttp://localhost:8080Ingress (Production)
Section intitulée « Ingress (Production) »If ingress is enabled:
# Access via configured hostnamehttp://kilimmanjaro.local # or your production domainMonitoring and Troubleshooting
Section intitulée « Monitoring and Troubleshooting »View Pod Status
Section intitulée « View Pod Status »# List podskubectl get pods -l app.kubernetes.io/component=frontend
# Describe podkubectl describe pod -l app.kubernetes.io/component=frontend
# Watch podskubectl get pods -l app.kubernetes.io/component=frontend -wView Logs
Section intitulée « View Logs »# Follow logskubectl logs -f deployment/kilimmanjaro-frontend
# Previous logs (if pod crashed)kubectl logs --previous deployment/kilimmanjaro-frontend
# All podskubectl logs -l app.kubernetes.io/component=frontend --tail=100Test Health Endpoint
Section intitulée « Test Health Endpoint »# Port forwardkubectl port-forward service/kilimmanjaro-frontend 8080:80
# Test healthcurl http://localhost:8080/health# Expected: healthyCommon Issues
Section intitulée « Common Issues »Pods Not Starting
Section intitulée « Pods Not Starting »# Check pod eventskubectl describe pod -l app.kubernetes.io/component=frontend
# Common causes:# - ImagePullBackOff: Image not built or not available# - CrashLoopBackOff: Application error# - Pending: Insufficient resourcesSolution for ImagePullBackOff:
# Ensure image is builtdocker images | grep kilimmanjaro/frontend
# For Minikube, use Minikube's Dockereval $(minikube docker-env)./scripts/k8s-build-image.shApplication Not Accessible
Section intitulée « Application Not Accessible »# Check servicekubectl get service kilimmanjaro-frontend
# For NodePort, get the portkubectl get service kilimmanjaro-frontend -o jsonpath='{.spec.ports[0].nodePort}'
# Use port-forward as alternativekubectl port-forward service/kilimmanjaro-frontend 8080:80API Calls Failing
Section intitulée « API Calls Failing »The frontend is trying to reach the backend but failing:
-
Check API URL in build:
REACT_APP_*est figé dans le bundle au moment dudocker build(CRA) : il n’y a pas de ConfigMap à inspecter — la valeur effective est celle du build arg passé à l’image.Fenêtre de terminal # Voir le build arg utilisé par l'image déployéekubectl get deployment kilimmanjaro-frontend \-o jsonpath='{.spec.template.spec.containers[0].image}'# Puis vérifier l'URL réellement embarquée dans le bundlekubectl exec deploy/kilimmanjaro-frontend -- \sh -c "grep -ho 'https\?://[^\"]*/api' /usr/share/nginx/html/static/js/*.js | sort -u" -
Rebuild with correct URL:
Fenêtre de terminal REACT_APP_API_URL="http://correct-backend-url/api" ./scripts/k8s-deploy.sh -
Verify backend is accessible:
Fenêtre de terminal # From within a podkubectl exec -it deployment/kilimmanjaro-frontend -- wget -O- http://backend-url/health
Debug Inside Pod
Section intitulée « Debug Inside Pod »# Open shell in podkubectl exec -it deployment/kilimmanjaro-frontend -- /bin/sh
# Check nginx configurationcat /etc/nginx/conf.d/default.conf
# Check served filesls -la /usr/share/nginx/html
# Test health endpointwget -O- http://localhost/healthProduction Deployment
Section intitulée « Production Deployment »Security Considerations
Section intitulée « Security Considerations »-
Use HTTPS with Ingress
ingress:enabled: trueannotations:cert-manager.io/cluster-issuer: letsencrypt-prodtls:- secretName: kilimmanjaro-tlshosts:- kilimmanjaro.com -
Set Resource Limits
frontend:resources:limits:cpu: 500mmemory: 512Mirequests:cpu: 250mmemory: 256Mi -
Enable Pod Security
- Use non-root user in container
- Read-only root filesystem
- Drop unnecessary capabilities
High Availability
Section intitulée « High Availability »frontend: replicaCount: 3 # Run multiple replicas
autoscaling: enabled: true minReplicas: 3 maxReplicas: 10 targetCPUUtilizationPercentage: 70
# Anti-affinity to spread across nodesPerformance Optimization
Section intitulée « Performance Optimization »- Enable CDN - Serve static assets from CDN
- Configure Caching - Already configured in nginx.conf
- Optimize Images - Use image optimization in build
- Code Splitting - React lazy loading
Monitoring
Section intitulée « Monitoring »Add monitoring tools:
# Prometheus + Grafanahelm repo add prometheus-community https://prometheus-community.github.io/helm-chartshelm install prometheus prometheus-community/kube-prometheus-stack
# Access Grafanakubectl port-forward svc/prometheus-grafana 3000:80Backup and Rollback
Section intitulée « Backup and Rollback »# List releaseshelm list
# Show historyhelm history kilimmanjaro
# Rollback to previous versionhelm rollback kilimmanjaro
# Rollback to specific revisionhelm rollback kilimmanjaro 2Helm Commands Reference
Section intitulée « Helm Commands Reference »# Installhelm install kilimmanjaro ./helm/kilimmanjaro-frontend
# Upgradehelm upgrade kilimmanjaro ./helm/kilimmanjaro-frontend
# Install or upgradehelm upgrade --install kilimmanjaro ./helm/kilimmanjaro-frontend
# Uninstallhelm uninstall kilimmanjaro
# List releaseshelm list
# Get valueshelm get values kilimmanjaro
# Dry runhelm install kilimmanjaro ./helm/kilimmanjaro-frontend --dry-run --debug
# Template renderinghelm template kilimmanjaro ./helm/kilimmanjaro-frontendEnvironment-Specific Deployments
Section intitulée « Environment-Specific Deployments »Development
Section intitulée « Development »helm install kilimmanjaro ./helm/kilimmanjaro-frontend \ -f helm/kilimmanjaro-frontend/values-local.yaml \ --set frontend.env.REACT_APP_API_URL="http://localhost:3000/api"helm install kilimmanjaro ./helm/kilimmanjaro-frontend \ --set frontend.env.REACT_APP_API_URL="https://api.staging.kilimmanjaro.com/api" \ --set frontend.replicaCount=2 \ --set ingress.enabled=true \ --set ingress.hosts[0].host="staging.kilimmanjaro.com"Production
Section intitulée « Production »helm install kilimmanjaro ./helm/kilimmanjaro-frontend \ --set frontend.env.REACT_APP_API_URL="https://api.kilimmanjaro.com/api" \ --set frontend.replicaCount=3 \ --set frontend.autoscaling.enabled=true \ --set ingress.enabled=true \ --set ingress.hosts[0].host="kilimmanjaro.com" \ --set ingress.tls[0].secretName="kilimmanjaro-tls" \ --set ingress.tls[0].hosts[0]="kilimmanjaro.com"Additional Resources
Section intitulée « Additional Resources »For issues:
- Check logs:
kubectl logs -f deployment/kilimmanjaro-frontend - Check events:
kubectl get events --sort-by=.metadata.creationTimestamp - Check pod description:
kubectl describe pod -l app.kubernetes.io/component=frontend