Aller au contenu

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.

  1. Kubernetes Cluster

    • Docker Desktop with Kubernetes enabled, or
    • Minikube, or
    • Any cloud Kubernetes service (GKE, EKS, AKS)
  2. Helm 3.0+

    Fenêtre de terminal
    # Install Helm (macOS)
    brew install helm
    # Verify installation
    helm version
  3. kubectl

    Fenêtre de terminal
    # Install kubectl (macOS)
    brew install kubectl
    # Verify installation
    kubectl version --client
  4. Docker

    Fenêtre de terminal
    # Verify Docker is installed
    docker --version

The fastest way to deploy to a local Kubernetes cluster:

Fenêtre de terminal
# Make scripts executable
chmod +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 --url

To clean up:

Fenêtre de terminal
./scripts/k8s-cleanup.sh

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

The application uses a multi-stage Docker build:

  1. Build Stage - Compiles React app with Node.js
  2. 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
  1. Enable Kubernetes

    • Open Docker Desktop → Settings → Kubernetes
    • Check “Enable Kubernetes”
    • Apply & Restart
  2. Deploy Application

    Fenêtre de terminal
    # Deploy with default settings
    ./scripts/k8s-deploy.sh
    # Or manually
    ./scripts/k8s-build-image.sh
    helm install kilimmanjaro ./helm/kilimmanjaro-frontend -f ./helm/kilimmanjaro-frontend/values-local.yaml
  3. Access Application

    Fenêtre de terminal
    # Frontend available at
    http://localhost:30080
  1. Start Minikube

    Fenêtre de terminal
    # Start with sufficient resources
    minikube start --cpus=2 --memory=4096
    # Use Minikube's Docker daemon
    eval $(minikube docker-env)
  2. Deploy Application

    Fenêtre de terminal
    ./scripts/k8s-deploy.sh
  3. Access Application

    Fenêtre de terminal
    # Get service URL
    minikube service kilimmanjaro-frontend --url
    # Or use port forward
    kubectl port-forward service/kilimmanjaro-frontend 8080:80

The main configuration is the API URL, which is baked into the build:

# values.yaml or values-local.yaml
frontend:
env:
REACT_APP_API_URL: "http://localhost:3000/api"

Create a custom values file:

custom-values.yaml
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: 70

Deploy with custom values:

Fenêtre de terminal
helm install kilimmanjaro ./helm/kilimmanjaro-frontend -f custom-values.yaml
frontend:
env:
REACT_APP_API_URL: "http://localhost:3000/api"
Fenêtre de terminal
# Get Minikube IP
minikube ip # e.g., x.x.x.x
# Configure in values file
frontend:
env:
REACT_APP_API_URL: "http://x.x.x.x:30000/api"

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.

  1. Build Docker Image

    Fenêtre de terminal
    # Build with custom API URL
    REACT_APP_API_URL="http://localhost:3000/api" ./scripts/k8s-build-image.sh
    # Or just
    ./scripts/k8s-build-image.sh # Uses default
  2. Install with Helm

    Fenêtre de terminal
    # Install
    helm install kilimmanjaro ./helm/kilimmanjaro-frontend -f ./helm/kilimmanjaro-frontend/values-local.yaml
    # Or upgrade if already installed
    helm upgrade kilimmanjaro ./helm/kilimmanjaro-frontend -f ./helm/kilimmanjaro-frontend/values-local.yaml
  3. Verify Deployment

    Fenêtre de terminal
    # Check pods
    kubectl get pods -l app.kubernetes.io/component=frontend
    # Check service
    kubectl get service kilimmanjaro-frontend
    # Check logs
    kubectl logs -f deployment/kilimmanjaro-frontend
Fenêtre de terminal
# Method 1: Use deployment script
./scripts/k8s-deploy.sh
# Method 2: Manual update
./scripts/k8s-build-image.sh
helm upgrade kilimmanjaro ./helm/kilimmanjaro-frontend
# Method 3: Rebuild with new API URL
REACT_APP_API_URL="https://api.production.com/api" ./scripts/k8s-build-image.sh
helm upgrade kilimmanjaro ./helm/kilimmanjaro-frontend \
--set frontend.env.REACT_APP_API_URL="https://api.production.com/api"
# Force pod restart to pick up new image
kubectl rollout restart deployment/kilimmanjaro-frontend
Fenêtre de terminal
# Get service details
kubectl get service kilimmanjaro-frontend
# Access directly
http://localhost:80
Fenêtre de terminal
# Get node port
kubectl get service kilimmanjaro-frontend
# Docker Desktop
http://localhost:30080
# Minikube
minikube service kilimmanjaro-frontend --url
Fenêtre de terminal
# Forward port
kubectl port-forward service/kilimmanjaro-frontend 8080:80
# Access at
http://localhost:8080

If ingress is enabled:

Fenêtre de terminal
# Access via configured hostname
http://kilimmanjaro.local # or your production domain
Fenêtre de terminal
# List pods
kubectl get pods -l app.kubernetes.io/component=frontend
# Describe pod
kubectl describe pod -l app.kubernetes.io/component=frontend
# Watch pods
kubectl get pods -l app.kubernetes.io/component=frontend -w
Fenêtre de terminal
# Follow logs
kubectl logs -f deployment/kilimmanjaro-frontend
# Previous logs (if pod crashed)
kubectl logs --previous deployment/kilimmanjaro-frontend
# All pods
kubectl logs -l app.kubernetes.io/component=frontend --tail=100
Fenêtre de terminal
# Port forward
kubectl port-forward service/kilimmanjaro-frontend 8080:80
# Test health
curl http://localhost:8080/health
# Expected: healthy
Fenêtre de terminal
# Check pod events
kubectl describe pod -l app.kubernetes.io/component=frontend
# Common causes:
# - ImagePullBackOff: Image not built or not available
# - CrashLoopBackOff: Application error
# - Pending: Insufficient resources

Solution for ImagePullBackOff:

Fenêtre de terminal
# Ensure image is built
docker images | grep kilimmanjaro/frontend
# For Minikube, use Minikube's Docker
eval $(minikube docker-env)
./scripts/k8s-build-image.sh
Fenêtre de terminal
# Check service
kubectl get service kilimmanjaro-frontend
# For NodePort, get the port
kubectl get service kilimmanjaro-frontend -o jsonpath='{.spec.ports[0].nodePort}'
# Use port-forward as alternative
kubectl port-forward service/kilimmanjaro-frontend 8080:80

The frontend is trying to reach the backend but failing:

  1. Check API URL in build:

    REACT_APP_* est figé dans le bundle au moment du docker 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ée
    kubectl get deployment kilimmanjaro-frontend \
    -o jsonpath='{.spec.template.spec.containers[0].image}'
    # Puis vérifier l'URL réellement embarquée dans le bundle
    kubectl exec deploy/kilimmanjaro-frontend -- \
    sh -c "grep -ho 'https\?://[^\"]*/api' /usr/share/nginx/html/static/js/*.js | sort -u"
  2. Rebuild with correct URL:

    Fenêtre de terminal
    REACT_APP_API_URL="http://correct-backend-url/api" ./scripts/k8s-deploy.sh
  3. Verify backend is accessible:

    Fenêtre de terminal
    # From within a pod
    kubectl exec -it deployment/kilimmanjaro-frontend -- wget -O- http://backend-url/health
Fenêtre de terminal
# Open shell in pod
kubectl exec -it deployment/kilimmanjaro-frontend -- /bin/sh
# Check nginx configuration
cat /etc/nginx/conf.d/default.conf
# Check served files
ls -la /usr/share/nginx/html
# Test health endpoint
wget -O- http://localhost/health
  1. Use HTTPS with Ingress

    ingress:
    enabled: true
    annotations:
    cert-manager.io/cluster-issuer: letsencrypt-prod
    tls:
    - secretName: kilimmanjaro-tls
    hosts:
    - kilimmanjaro.com
  2. Set Resource Limits

    frontend:
    resources:
    limits:
    cpu: 500m
    memory: 512Mi
    requests:
    cpu: 250m
    memory: 256Mi
  3. Enable Pod Security

    • Use non-root user in container
    • Read-only root filesystem
    • Drop unnecessary capabilities
frontend:
replicaCount: 3 # Run multiple replicas
autoscaling:
enabled: true
minReplicas: 3
maxReplicas: 10
targetCPUUtilizationPercentage: 70
# Anti-affinity to spread across nodes
  1. Enable CDN - Serve static assets from CDN
  2. Configure Caching - Already configured in nginx.conf
  3. Optimize Images - Use image optimization in build
  4. Code Splitting - React lazy loading

Add monitoring tools:

Fenêtre de terminal
# Prometheus + Grafana
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm install prometheus prometheus-community/kube-prometheus-stack
# Access Grafana
kubectl port-forward svc/prometheus-grafana 3000:80
Fenêtre de terminal
# List releases
helm list
# Show history
helm history kilimmanjaro
# Rollback to previous version
helm rollback kilimmanjaro
# Rollback to specific revision
helm rollback kilimmanjaro 2
Fenêtre de terminal
# Install
helm install kilimmanjaro ./helm/kilimmanjaro-frontend
# Upgrade
helm upgrade kilimmanjaro ./helm/kilimmanjaro-frontend
# Install or upgrade
helm upgrade --install kilimmanjaro ./helm/kilimmanjaro-frontend
# Uninstall
helm uninstall kilimmanjaro
# List releases
helm list
# Get values
helm get values kilimmanjaro
# Dry run
helm install kilimmanjaro ./helm/kilimmanjaro-frontend --dry-run --debug
# Template rendering
helm template kilimmanjaro ./helm/kilimmanjaro-frontend
Fenêtre de terminal
helm install kilimmanjaro ./helm/kilimmanjaro-frontend \
-f helm/kilimmanjaro-frontend/values-local.yaml \
--set frontend.env.REACT_APP_API_URL="http://localhost:3000/api"
Fenêtre de terminal
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"
Fenêtre de terminal
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"

For issues:

  1. Check logs: kubectl logs -f deployment/kilimmanjaro-frontend
  2. Check events: kubectl get events --sort-by=.metadata.creationTimestamp
  3. Check pod description: kubectl describe pod -l app.kubernetes.io/component=frontend