#!/usr/bin/env bash set -euo pipefail # Create a simpler nginx.conf that just proxies /api cat > /tmp/fixed-nginx.conf << 'EOF' server { listen 80; server_name localhost; root /usr/share/nginx/html; index index.html; # Proxy API requests without trailing slash issues location /api { proxy_pass http://backend-service:4000; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; } # Handle React router paths location / { try_files $uri $uri/ /index.html; } } EOF # Create ConfigMap from this nginx.conf kubectl create configmap nginx-fixed-config -n sk1 --from-file=nginx.conf=/tmp/fixed-nginx.conf --dry-run=client -o yaml | kubectl apply -f - # Update the frontend deployment to use this ConfigMap cat > /tmp/fixed-frontend-update.yaml << EOF apiVersion: apps/v1 kind: Deployment metadata: name: frontend namespace: sk1 spec: template: spec: containers: - name: frontend volumeMounts: - name: nginx-config mountPath: /etc/nginx/conf.d/default.conf subPath: nginx.conf volumes: - name: nginx-config configMap: name: nginx-fixed-config EOF # Apply the update as a patch kubectl patch deployment frontend -n sk1 --patch-file /tmp/fixed-frontend-update.yaml echo "Updated frontend nginx configuration" kubectl rollout restart deployment frontend -n sk1