59 lines
1.6 KiB
Bash
Executable File
59 lines
1.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
# Create a corrected nginx.conf
|
|
cat > /tmp/nginx.conf << 'EOF'
|
|
server {
|
|
listen 80;
|
|
server_name localhost;
|
|
root /usr/share/nginx/html;
|
|
index index.html;
|
|
|
|
# Redirect API requests to the backend service
|
|
location /api/ {
|
|
# Important: use backend-service.sk1.svc.cluster.local for the full internal DNS name
|
|
proxy_pass http://backend-service.sk1.svc.cluster.local: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;
|
|
|
|
# Add debugging headers
|
|
add_header X-Debug-Target "backend-service.sk1.svc.cluster.local:4000" always;
|
|
}
|
|
|
|
# Serve static assets
|
|
location / {
|
|
try_files $uri $uri/ /index.html;
|
|
}
|
|
}
|
|
EOF
|
|
|
|
# Create a ConfigMap from this nginx.conf
|
|
kubectl create configmap nginx-config -n sk1 --from-file=/tmp/nginx.conf --dry-run=client -o yaml | kubectl apply -f -
|
|
|
|
# Update the frontend deployment to use this ConfigMap
|
|
cat > /tmp/frontend-deployment-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-config
|
|
EOF
|
|
|
|
# Apply the update as a patch
|
|
kubectl patch deployment frontend -n sk1 --patch-file /tmp/frontend-deployment-update.yaml |