final assignment
This commit is contained in:
parent
9b27289a25
commit
507260f200
@ -1,63 +0,0 @@
|
||||
# Create a fixed deployment file
|
||||
cat > fixed-backend.yml << EOF
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: backend
|
||||
namespace: sk1
|
||||
spec:
|
||||
replicas: 2
|
||||
selector:
|
||||
matchLabels:
|
||||
app: backend
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: backend
|
||||
spec:
|
||||
containers:
|
||||
- name: backend
|
||||
image: gcr.io/$(gcloud config get-value project)/backend:latest
|
||||
resources:
|
||||
limits:
|
||||
cpu: "500m"
|
||||
memory: "512Mi"
|
||||
requests:
|
||||
cpu: "200m"
|
||||
memory: "256Mi"
|
||||
ports:
|
||||
- containerPort: 4000
|
||||
env:
|
||||
- name: PORT
|
||||
value: "4000"
|
||||
- name: MONGO_URI
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: mongodb-secret
|
||||
key: MONGO_URI
|
||||
- name: JWT_SECRET
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: mongodb-secret
|
||||
key: JWT_SECRET
|
||||
- name: GOOGLE_PLACES_API_KEY
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: mongodb-secret
|
||||
key: GOOGLE_PLACES_API_KEY
|
||||
livenessProbe:
|
||||
httpGet:
|
||||
path: /api
|
||||
port: 4000
|
||||
initialDelaySeconds: 30
|
||||
periodSeconds: 20
|
||||
readinessProbe:
|
||||
httpGet:
|
||||
path: /api
|
||||
port: 4000
|
||||
initialDelaySeconds: 15
|
||||
periodSeconds: 10
|
||||
EOF
|
||||
|
||||
# Apply the fixed deployment
|
||||
kubectl apply -f fixed-backend.yml
|
@ -1,57 +0,0 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: backend
|
||||
namespace: sk1
|
||||
spec:
|
||||
replicas: 2
|
||||
selector:
|
||||
matchLabels:
|
||||
app: backend
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: backend
|
||||
spec:
|
||||
containers:
|
||||
- name: backend
|
||||
image: gcr.io/leafy-racer-458817-c0/backend:latest
|
||||
resources:
|
||||
limits:
|
||||
cpu: "500m"
|
||||
memory: "512Mi"
|
||||
requests:
|
||||
cpu: "200m"
|
||||
memory: "256Mi"
|
||||
ports:
|
||||
- containerPort: 4000
|
||||
env:
|
||||
- name: PORT
|
||||
value: "4000"
|
||||
- name: MONGO_URI
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: mongodb-secret
|
||||
key: MONGO_URI
|
||||
- name: JWT_SECRET
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: mongodb-secret
|
||||
key: JWT_SECRET
|
||||
- name: GOOGLE_PLACES_API_KEY
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: mongodb-secret
|
||||
key: GOOGLE_PLACES_API_KEY
|
||||
livenessProbe:
|
||||
httpGet:
|
||||
path: /api
|
||||
port: 4000
|
||||
initialDelaySeconds: 30
|
||||
periodSeconds: 20
|
||||
readinessProbe:
|
||||
httpGet:
|
||||
path: /api
|
||||
port: 4000
|
||||
initialDelaySeconds: 15
|
||||
periodSeconds: 10
|
9
sk1/k8s/secret-example.yml
Normal file
9
sk1/k8s/secret-example.yml
Normal file
@ -0,0 +1,9 @@
|
||||
apiVersion: v1
|
||||
kind: Secret
|
||||
metadata:
|
||||
name: mongodb-secret
|
||||
type: Opaque
|
||||
stringData:
|
||||
MONGO_URI: "mongo cluster connection addrses"
|
||||
JWT_SECRET: "Add JWT secret here"
|
||||
GOOGLE_PLACES_API_KEY: "add google places api key here"
|
@ -1 +0,0 @@
|
||||
frontend/Dockerfile verify-service.sh update-nginx-config.sh update-frontend.sh test-routes.sh test-network.sh test-connection.sh test-backend.sh test-api.sh simple-backend.sh resilient-deploy.sh refresh-connection.sh rebuild-backend.sh fixed-nginx-conf.yaml sk1-ingress.yaml fix-service-routes.sh fix-react-config.sh fix-ingress.sh fix-frontend.sh fix-frontend-nginx.sh fix-deployments.sh fix-backend-service.sh fix-backend-health.sh fix-add-routes.sh deploy-fixed-backend.sh debug-instructions.txt create-ingress.sh complete-ingress.yaml complete-ingress-setup.sh complete-fix.sh certificate.yaml backend-fixed-deployment.yaml
|
@ -1,68 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# Create a ConfigMap with route patches for the backend
|
||||
cat > /tmp/route-patches.js << 'EOF'
|
||||
// Root route
|
||||
app.get('/', (req, res) => {
|
||||
res.json({ message: 'Welcome to the API' });
|
||||
});
|
||||
|
||||
// Health check endpoint
|
||||
app.get('/api', (req, res) => {
|
||||
res.json({ status: 'ok', message: 'API is healthy' });
|
||||
});
|
||||
|
||||
// Update existing routes if needed
|
||||
app.get('/api/health', (req, res) => {
|
||||
res.json({ status: 'ok' });
|
||||
});
|
||||
EOF
|
||||
|
||||
kubectl create configmap route-patches -n sk1 --from-file=routes.js=/tmp/route-patches.js --dry-run=client -o yaml | kubectl apply -f -
|
||||
|
||||
# Create a patch for the backend deployment to inject these routes
|
||||
cat > /tmp/backend-patch-routes.yaml << EOF
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: backend
|
||||
namespace: sk1
|
||||
spec:
|
||||
template:
|
||||
spec:
|
||||
containers:
|
||||
- name: backend
|
||||
env:
|
||||
- name: DEBUG
|
||||
value: "express:*"
|
||||
# Add script to update routes on startup
|
||||
lifecycle:
|
||||
postStart:
|
||||
exec:
|
||||
command:
|
||||
- sh
|
||||
- -c
|
||||
- |
|
||||
echo "Patching routes..."
|
||||
cat /routes/routes.js >> /app/index.js
|
||||
# Force Express to reload routes
|
||||
kill -SIGHUP 1
|
||||
volumeMounts:
|
||||
- name: route-patches
|
||||
mountPath: /routes
|
||||
volumes:
|
||||
- name: route-patches
|
||||
configMap:
|
||||
name: route-patches
|
||||
EOF
|
||||
|
||||
# Apply the patch
|
||||
kubectl apply -f /tmp/backend-patch-routes.yaml
|
||||
|
||||
# Restart backend to apply changes
|
||||
kubectl rollout restart deployment backend -n sk1
|
||||
|
||||
echo "Added missing API routes to backend"
|
||||
echo "Waiting for backend to restart..."
|
||||
kubectl rollout status deployment backend -n sk1
|
@ -1,42 +0,0 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: backend-fixed
|
||||
namespace: sk1
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: backend-fixed
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: backend-fixed
|
||||
spec:
|
||||
containers:
|
||||
- name: backend
|
||||
image: gcr.io/leafy-racer-458817-c0/backend-fixed:latest
|
||||
env:
|
||||
- name: PORT
|
||||
value: "4000"
|
||||
- name: HOST
|
||||
value: "0.0.0.0"
|
||||
- name: MONGO_URI
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: mongodb-secret
|
||||
key: MONGO_URI
|
||||
ports:
|
||||
- containerPort: 4000
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: backend-service
|
||||
namespace: sk1
|
||||
spec:
|
||||
selector:
|
||||
app: backend-fixed
|
||||
ports:
|
||||
- port: 4000
|
||||
targetPort: 4000
|
@ -1,8 +0,0 @@
|
||||
apiVersion: networking.gke.io/v1
|
||||
kind: ManagedCertificate
|
||||
metadata:
|
||||
name: sk1-cert
|
||||
namespace: sk1
|
||||
spec:
|
||||
domains:
|
||||
- nudges.works
|
@ -1,352 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# Get project ID
|
||||
PROJECT=$(gcloud config get-value project)
|
||||
|
||||
echo "🔍 Checking current status..."
|
||||
kubectl get pods -n sk1
|
||||
|
||||
echo "🧹 Cleaning up any broken configurations..."
|
||||
# Delete the debug pods we created earlier
|
||||
kubectl delete pod debug-react -n sk1 --ignore-not-found
|
||||
kubectl delete pod test-route -n sk1 --ignore-not-found
|
||||
|
||||
echo "🔄 Creating a complete backend with all required routes..."
|
||||
|
||||
# Create a temporary file with our complete backend app
|
||||
cat > /tmp/complete-backend.js << 'EOF'
|
||||
const express = require('express');
|
||||
const cors = require('cors');
|
||||
const mongoose = require('mongoose');
|
||||
const app = express();
|
||||
const port = process.env.PORT || 4000;
|
||||
const host = process.env.HOST || '0.0.0.0';
|
||||
|
||||
// Middleware
|
||||
app.use(cors());
|
||||
app.use(express.json());
|
||||
app.use(express.urlencoded({ extended: true }));
|
||||
|
||||
// Root route
|
||||
app.get('/', (req, res) => {
|
||||
res.json({ message: 'Welcome to the API' });
|
||||
});
|
||||
|
||||
// Health check endpoint
|
||||
app.get('/api', (req, res) => {
|
||||
res.json({ status: 'ok', message: 'API is healthy' });
|
||||
});
|
||||
|
||||
// Health check endpoint
|
||||
app.get('/api/health', (req, res) => {
|
||||
res.json({ status: 'ok' });
|
||||
});
|
||||
|
||||
// Service routes
|
||||
app.get('/api/services/:serviceType', (req, res) => {
|
||||
const serviceType = req.params.serviceType;
|
||||
const { radius, page, sortBy, order, lat, lon } = req.query;
|
||||
|
||||
console.log(`Received request for ${serviceType} services`);
|
||||
console.log(`Query params: radius=${radius}, page=${page}, sortBy=${sortBy}, order=${order}, lat=${lat}, lon=${lon}`);
|
||||
|
||||
// Return mock data for any service type
|
||||
res.json({
|
||||
success: true,
|
||||
services: [
|
||||
{
|
||||
id: 1,
|
||||
name: `${serviceType} Service 1`,
|
||||
description: `Professional ${serviceType} service`,
|
||||
price: Math.floor(Math.random() * 50) + 20,
|
||||
distance: parseFloat((Math.random() * 5).toFixed(1)),
|
||||
rating: parseFloat((Math.random() * 2 + 3).toFixed(1))
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
name: `${serviceType} Service 2`,
|
||||
description: `Expert ${serviceType} provider`,
|
||||
price: Math.floor(Math.random() * 50) + 20,
|
||||
distance: parseFloat((Math.random() * 5).toFixed(1)),
|
||||
rating: parseFloat((Math.random() * 2 + 3).toFixed(1))
|
||||
}
|
||||
],
|
||||
pagination: {
|
||||
currentPage: parseInt(page) || 1,
|
||||
totalPages: 3,
|
||||
totalResults: 6
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Authentication endpoints
|
||||
app.post('/api/auth/login', (req, res) => {
|
||||
console.log('Login attempt:', req.body);
|
||||
|
||||
res.json({
|
||||
success: true,
|
||||
token: "mock-jwt-token",
|
||||
user: {
|
||||
id: 1,
|
||||
name: "Test User",
|
||||
email: req.body.email || "test@example.com"
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
app.post('/api/auth/register', (req, res) => {
|
||||
console.log('Registration attempt:', req.body);
|
||||
|
||||
res.json({
|
||||
success: true,
|
||||
message: "User registered successfully",
|
||||
user: {
|
||||
id: new Date().getTime(),
|
||||
name: req.body.name || "New User",
|
||||
email: req.body.email || "new@example.com"
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// MongoDB connection
|
||||
const MONGO_URI = process.env.MONGO_URI;
|
||||
if (MONGO_URI) {
|
||||
mongoose.connect(MONGO_URI)
|
||||
.then(() => console.log('✅ MongoDB connected'))
|
||||
.catch(err => console.error('MongoDB connection error:', err));
|
||||
}
|
||||
|
||||
// Error handling middleware
|
||||
app.use((err, req, res, next) => {
|
||||
console.error('Error:', err);
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: 'Server error',
|
||||
error: process.env.NODE_ENV === 'development' ? err.message : 'Internal server error'
|
||||
});
|
||||
});
|
||||
|
||||
// Handle 404s
|
||||
app.use((req, res) => {
|
||||
console.log(`404: ${req.method} ${req.path}`);
|
||||
res.status(404).json({
|
||||
success: false,
|
||||
message: 'API endpoint not found'
|
||||
});
|
||||
});
|
||||
|
||||
// Start server
|
||||
app.listen(port, host, () => {
|
||||
console.log(`🚀 Server running on http://${host}:${port}`);
|
||||
});
|
||||
EOF
|
||||
|
||||
# Create a package.json file
|
||||
cat > /tmp/package.json << 'EOF'
|
||||
{
|
||||
"name": "backend",
|
||||
"version": "1.0.0",
|
||||
"description": "Backend for Nudges Works application",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"start": "node index.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"cors": "^2.8.5",
|
||||
"express": "^4.18.2",
|
||||
"mongoose": "^7.0.3"
|
||||
}
|
||||
}
|
||||
EOF
|
||||
|
||||
# Create a Dockerfile
|
||||
cat > /tmp/Dockerfile << 'EOF'
|
||||
FROM node:20-alpine
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY package.json .
|
||||
RUN npm install
|
||||
|
||||
COPY index.js .
|
||||
|
||||
EXPOSE 4000
|
||||
|
||||
CMD ["node", "index.js"]
|
||||
EOF
|
||||
|
||||
# Create a temporary directory and copy files
|
||||
rm -rf /tmp/backend-build || true
|
||||
mkdir -p /tmp/backend-build
|
||||
cp /tmp/complete-backend.js /tmp/backend-build/index.js
|
||||
cp /tmp/package.json /tmp/backend-build/package.json
|
||||
cp /tmp/Dockerfile /tmp/backend-build/Dockerfile
|
||||
|
||||
# Build and push the image
|
||||
echo "🏗️ Building and pushing new backend image..."
|
||||
cd /tmp/backend-build
|
||||
gcloud builds submit --tag gcr.io/${PROJECT}/backend-complete:latest
|
||||
|
||||
# Create a deployment with the new image
|
||||
cat > /tmp/backend-complete.yaml << EOF
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: backend
|
||||
namespace: sk1
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: backend
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: backend
|
||||
spec:
|
||||
containers:
|
||||
- name: backend
|
||||
image: gcr.io/${PROJECT}/backend-complete:latest
|
||||
resources:
|
||||
limits:
|
||||
cpu: "0.5"
|
||||
memory: "512Mi"
|
||||
requests:
|
||||
cpu: "0.2"
|
||||
memory: "256Mi"
|
||||
ports:
|
||||
- containerPort: 4000
|
||||
env:
|
||||
- name: PORT
|
||||
value: "4000"
|
||||
- name: HOST
|
||||
value: "0.0.0.0"
|
||||
- name: MONGO_URI
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: mongodb-secret
|
||||
key: MONGO_URI
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: backend-service
|
||||
namespace: sk1
|
||||
spec:
|
||||
selector:
|
||||
app: backend
|
||||
ports:
|
||||
- port: 4000
|
||||
targetPort: 4000
|
||||
EOF
|
||||
|
||||
# Apply the deployment
|
||||
echo "📦 Applying new backend deployment..."
|
||||
kubectl apply -f /tmp/backend-complete.yaml
|
||||
|
||||
# Update the frontend nginx config to ensure it's working correctly
|
||||
cat > /tmp/fixed-nginx.conf << 'EOF'
|
||||
server {
|
||||
listen 80;
|
||||
server_name localhost;
|
||||
root /usr/share/nginx/html;
|
||||
index index.html;
|
||||
|
||||
# Fix for API routing - explicit location block for various endpoints
|
||||
location /api/services/ {
|
||||
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_set_header X-Real-IP $remote_addr;
|
||||
proxy_cache_bypass $http_upgrade;
|
||||
}
|
||||
|
||||
location /api/auth/ {
|
||||
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_set_header X-Real-IP $remote_addr;
|
||||
proxy_cache_bypass $http_upgrade;
|
||||
}
|
||||
|
||||
# General API requests
|
||||
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_set_header X-Real-IP $remote_addr;
|
||||
proxy_cache_bypass $http_upgrade;
|
||||
}
|
||||
|
||||
# All other requests go to the React app
|
||||
location / {
|
||||
try_files $uri $uri/ /index.html;
|
||||
}
|
||||
}
|
||||
EOF
|
||||
|
||||
# Create a ConfigMap for the new nginx configuration
|
||||
kubectl create configmap fixed-nginx-conf -n sk1 --from-file=nginx.conf=/tmp/fixed-nginx.conf -o yaml --dry-run=client | kubectl apply -f -
|
||||
|
||||
# Update the frontend deployment to use the new ConfigMap
|
||||
kubectl patch deployment frontend -n sk1 --type=strategic --patch '
|
||||
{
|
||||
"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": "fixed-nginx-conf"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
'
|
||||
|
||||
# Restart frontend
|
||||
kubectl rollout restart deployment frontend -n sk1
|
||||
|
||||
echo "⏱️ Waiting for deployments to be ready..."
|
||||
kubectl rollout status deployment backend -n sk1
|
||||
kubectl rollout status deployment frontend -n sk1
|
||||
|
||||
echo "✅ Deployment complete!"
|
||||
echo "Testing backend API directly..."
|
||||
kubectl run api-test --image=curlimages/curl -n sk1 --rm -it -- sh -c '
|
||||
echo "Testing /api endpoint:"
|
||||
curl -s http://backend-service:4000/api
|
||||
echo ""
|
||||
echo "Testing /api/services/assembly endpoint:"
|
||||
curl -s http://backend-service:4000/api/services/assembly
|
||||
echo ""
|
||||
echo "Testing /api/auth/login endpoint:"
|
||||
curl -s -X POST -H "Content-Type: application/json" -d '\''{"email":"test@example.com","password":"password"}'\'' http://backend-service:4000/api/auth/login
|
||||
echo ""
|
||||
'
|
||||
|
||||
echo "🎉 Your application should now be working properly at https://nudges.works"
|
||||
echo "If you're still seeing issues, try clearing your browser cache or using a private/incognito window"
|
@ -1,167 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# Get project ID
|
||||
PROJECT=$(gcloud config get-value project)
|
||||
|
||||
echo "🔍 Checking if certificate exists..."
|
||||
if ! kubectl get managedcertificate sk1-cert -n sk1 2>/dev/null; then
|
||||
echo "🔒 Creating managed certificate..."
|
||||
# Create certificate
|
||||
cat > certificate.yaml << EOF
|
||||
apiVersion: networking.gke.io/v1
|
||||
kind: ManagedCertificate
|
||||
metadata:
|
||||
name: sk1-cert
|
||||
namespace: sk1
|
||||
spec:
|
||||
domains:
|
||||
- nudges.works
|
||||
EOF
|
||||
|
||||
kubectl apply -f certificate.yaml
|
||||
echo "✅ Certificate created"
|
||||
else
|
||||
echo "✅ Certificate already exists"
|
||||
fi
|
||||
|
||||
echo "🔍 Checking if static IP exists..."
|
||||
if ! gcloud compute addresses describe sk1-static-ip --global &>/dev/null; then
|
||||
echo "🌐 Creating static IP..."
|
||||
# Create static IP
|
||||
gcloud compute addresses create sk1-static-ip --global
|
||||
echo "✅ Static IP created"
|
||||
else
|
||||
echo "✅ Static IP already exists"
|
||||
fi
|
||||
|
||||
# Get the static IP
|
||||
IP=$(gcloud compute addresses describe sk1-static-ip --global --format="value(address)")
|
||||
echo "📝 Using static IP: $IP"
|
||||
|
||||
echo "🏗️ Creating ingress resource..."
|
||||
# Create ingress resource
|
||||
cat > complete-ingress.yaml << EOF
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: Ingress
|
||||
metadata:
|
||||
name: sk1-ingress
|
||||
namespace: sk1
|
||||
annotations:
|
||||
kubernetes.io/ingress.global-static-ip-name: sk1-static-ip
|
||||
networking.gke.io/managed-certificates: sk1-cert
|
||||
kubernetes.io/ingress.class: "gce"
|
||||
spec:
|
||||
rules:
|
||||
- host: nudges.works
|
||||
http:
|
||||
paths:
|
||||
- path: /api/
|
||||
pathType: Prefix
|
||||
backend:
|
||||
service:
|
||||
name: backend-service
|
||||
port:
|
||||
number: 4000
|
||||
- path: /
|
||||
pathType: Prefix
|
||||
backend:
|
||||
service:
|
||||
name: frontend-service
|
||||
port:
|
||||
number: 80
|
||||
EOF
|
||||
|
||||
# Apply the ingress configuration
|
||||
kubectl apply -f complete-ingress.yaml
|
||||
|
||||
echo "⏱️ Waiting for ingress to initialize..."
|
||||
sleep 10
|
||||
|
||||
echo "🔍 Checking ingress status..."
|
||||
kubectl get ingress -n sk1
|
||||
|
||||
# Create a special nginx configuration for frontend to handle direct requests to backend
|
||||
echo "📝 Updating frontend nginx configuration to correctly handle API requests..."
|
||||
cat > fixed-nginx-conf.yaml << EOF
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: fixed-nginx-conf
|
||||
namespace: sk1
|
||||
data:
|
||||
nginx.conf: |
|
||||
server {
|
||||
listen 80;
|
||||
server_name localhost;
|
||||
root /usr/share/nginx/html;
|
||||
index index.html;
|
||||
|
||||
# All API requests should go to backend service
|
||||
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_set_header X-Real-IP \$remote_addr;
|
||||
proxy_cache_bypass \$http_upgrade;
|
||||
}
|
||||
|
||||
# All other requests go to the React app
|
||||
location / {
|
||||
try_files \$uri \$uri/ /index.html;
|
||||
}
|
||||
}
|
||||
EOF
|
||||
|
||||
kubectl apply -f fixed-nginx-conf.yaml
|
||||
|
||||
# Update frontend to use this config
|
||||
kubectl patch deployment frontend -n sk1 --type=strategic --patch '
|
||||
{
|
||||
"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": "fixed-nginx-conf"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
'
|
||||
|
||||
echo "🔄 Restarting pods to ensure clean configuration..."
|
||||
kubectl rollout restart deployment frontend -n sk1
|
||||
kubectl rollout restart deployment backend -n sk1
|
||||
|
||||
echo "⏱️ Waiting for deployments to restart..."
|
||||
kubectl rollout status deployment frontend -n sk1
|
||||
kubectl rollout status deployment backend -n sk1
|
||||
|
||||
echo "✅ Setup complete!"
|
||||
echo ""
|
||||
echo "Your application should now be accessible at: https://nudges.works"
|
||||
echo "Note: It may take 5-10 minutes for the DNS and certificate to propagate completely."
|
||||
echo ""
|
||||
echo "You can test the API directly with: curl https://nudges.works/api"
|
||||
echo ""
|
||||
echo "If you still encounter issues, try clearing your browser cache or using an incognito window."
|
@ -1,28 +0,0 @@
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: Ingress
|
||||
metadata:
|
||||
name: sk1-ingress
|
||||
namespace: sk1
|
||||
annotations:
|
||||
kubernetes.io/ingress.global-static-ip-name: sk1-static-ip
|
||||
networking.gke.io/managed-certificates: sk1-cert
|
||||
kubernetes.io/ingress.class: "gce"
|
||||
spec:
|
||||
rules:
|
||||
- host: nudges.works
|
||||
http:
|
||||
paths:
|
||||
- path: /api/
|
||||
pathType: Prefix
|
||||
backend:
|
||||
service:
|
||||
name: backend-service
|
||||
port:
|
||||
number: 4000
|
||||
- path: /
|
||||
pathType: Prefix
|
||||
backend:
|
||||
service:
|
||||
name: frontend-service
|
||||
port:
|
||||
number: 80
|
@ -1,55 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# Get project ID
|
||||
PROJECT=$(gcloud config get-value project)
|
||||
|
||||
echo "🏗️ Creating new ingress configuration..."
|
||||
|
||||
# Create ingress resource
|
||||
cat > sk1-ingress.yaml << EOF
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: Ingress
|
||||
metadata:
|
||||
name: sk1-ingress
|
||||
namespace: sk1
|
||||
annotations:
|
||||
kubernetes.io/ingress.global-static-ip-name: sk1-static-ip
|
||||
networking.gke.io/managed-certificates: sk1-cert
|
||||
spec:
|
||||
rules:
|
||||
- host: nudges.works
|
||||
http:
|
||||
paths:
|
||||
- path: /api
|
||||
pathType: Prefix
|
||||
backend:
|
||||
service:
|
||||
name: backend-service
|
||||
port:
|
||||
number: 4000
|
||||
- path: /
|
||||
pathType: Prefix
|
||||
backend:
|
||||
service:
|
||||
name: frontend-service
|
||||
port:
|
||||
number: 80
|
||||
EOF
|
||||
|
||||
# Apply the ingress configuration
|
||||
kubectl apply -f sk1-ingress.yaml
|
||||
|
||||
echo "⏱️ Waiting for ingress to initialize..."
|
||||
sleep 10
|
||||
|
||||
echo "🔍 Checking ingress status..."
|
||||
kubectl get ingress -n sk1
|
||||
|
||||
echo "✅ Ingress created!"
|
||||
echo ""
|
||||
echo "It may take a few minutes for the ingress to provision completely."
|
||||
echo "Try accessing your app at https://nudges.works in 5-10 minutes."
|
||||
echo ""
|
||||
echo "In the meantime, you can check your backend and frontend services:"
|
||||
echo "kubectl get services -n sk1"
|
@ -1,13 +0,0 @@
|
||||
To debug your React application's API calls:
|
||||
|
||||
1. Open https://nudges.works in Chrome/Edge
|
||||
2. Press F12 to open Developer Tools
|
||||
3. Go to the Network tab
|
||||
4. Try to log in or use features that should call the API
|
||||
5. Look for failed API calls (in red)
|
||||
6. Check the URL of the requests - they should start with /api/...
|
||||
|
||||
Common issues:
|
||||
- Frontend might be calling http://localhost:4000/api instead of /api
|
||||
- API endpoints in React might not match backend endpoints
|
||||
- Authentication headers might be missing or incorrect
|
@ -1,145 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# Get project ID
|
||||
PROJECT=$(gcloud config get-value project)
|
||||
|
||||
# Reconnect to cluster in case connection timed out
|
||||
echo "🔄 Refreshing connection to GKE cluster..."
|
||||
gcloud container clusters get-credentials sk1-cluster --zone us-central1-a --project ${PROJECT}
|
||||
|
||||
# Create a temporary file with our complete backend app
|
||||
cat > /tmp/complete-backend.js << 'EOF'
|
||||
const express = require('express');
|
||||
const cors = require('cors');
|
||||
const mongoose = require('mongoose');
|
||||
const app = express();
|
||||
const port = process.env.PORT || 4000;
|
||||
const host = process.env.HOST || 'localhost';
|
||||
|
||||
// Middleware
|
||||
app.use(cors());
|
||||
app.use(express.json());
|
||||
|
||||
// Root route
|
||||
app.get('/', (req, res) => {
|
||||
res.json({ message: 'Welcome to the API' });
|
||||
});
|
||||
|
||||
// Health check endpoint
|
||||
app.get('/api', (req, res) => {
|
||||
res.json({ status: 'ok', message: 'API is healthy' });
|
||||
});
|
||||
|
||||
// Health check endpoint
|
||||
app.get('/api/health', (req, res) => {
|
||||
res.json({ status: 'ok' });
|
||||
});
|
||||
|
||||
// MongoDB connection
|
||||
const MONGO_URI = process.env.MONGO_URI;
|
||||
if (MONGO_URI) {
|
||||
mongoose.connect(MONGO_URI)
|
||||
.then(() => console.log('✅ MongoDB connected'))
|
||||
.catch(err => console.error('MongoDB connection error:', err));
|
||||
}
|
||||
|
||||
// Start server
|
||||
app.listen(port, host, () => {
|
||||
console.log(`🚀 Server running on http://${host}:${port}`);
|
||||
});
|
||||
EOF
|
||||
|
||||
# Create a Dockerfile for our custom backend
|
||||
cat > /tmp/Dockerfile.backend << 'EOF'
|
||||
FROM node:20-alpine
|
||||
WORKDIR /app
|
||||
COPY package.json .
|
||||
RUN npm install express cors mongoose
|
||||
COPY . .
|
||||
EXPOSE 4000
|
||||
CMD ["node", "index.js"]
|
||||
EOF
|
||||
|
||||
# Create a directory for our custom backend
|
||||
mkdir -p /tmp/custom-backend
|
||||
cp /tmp/complete-backend.js /tmp/custom-backend/index.js
|
||||
cp /tmp/Dockerfile.backend /tmp/custom-backend/Dockerfile
|
||||
|
||||
# Create a basic package.json
|
||||
cat > /tmp/custom-backend/package.json << 'EOF'
|
||||
{
|
||||
"name": "backend",
|
||||
"version": "1.0.0",
|
||||
"description": "Custom backend for sk1",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"cors": "^2.8.5",
|
||||
"express": "^4.18.2",
|
||||
"mongoose": "^7.0.3"
|
||||
}
|
||||
}
|
||||
EOF
|
||||
|
||||
echo "🏗️ Building custom backend image..."
|
||||
cd /tmp/custom-backend
|
||||
gcloud builds submit --tag "gcr.io/${PROJECT}/backend-fixed:latest" .
|
||||
cd -
|
||||
|
||||
# Create a new deployment using our fixed image
|
||||
cat > /tmp/fixed-backend-deployment.yaml << EOF
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: backend-fixed
|
||||
namespace: sk1
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: backend-fixed
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: backend-fixed
|
||||
spec:
|
||||
containers:
|
||||
- name: backend
|
||||
image: gcr.io/${PROJECT}/backend-fixed:latest
|
||||
env:
|
||||
- name: PORT
|
||||
value: "4000"
|
||||
- name: HOST
|
||||
value: "0.0.0.0"
|
||||
- name: MONGO_URI
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: mongodb-secret
|
||||
key: MONGO_URI
|
||||
ports:
|
||||
- containerPort: 4000
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: backend-service
|
||||
namespace: sk1
|
||||
spec:
|
||||
selector:
|
||||
app: backend-fixed
|
||||
ports:
|
||||
- port: 4000
|
||||
targetPort: 4000
|
||||
EOF
|
||||
|
||||
echo "📦 Deploying fixed backend..."
|
||||
kubectl apply -f /tmp/fixed-backend-deployment.yaml
|
||||
|
||||
echo "⏱️ Waiting for deployment to be available..."
|
||||
kubectl rollout status deployment/backend-fixed -n sk1
|
||||
|
||||
echo "🔍 Checking for running pods..."
|
||||
kubectl get pods -n sk1 -l app=backend-fixed
|
||||
|
||||
echo "✅ Deployment complete. Testing backend health..."
|
||||
kubectl exec -it netshoot -n sk1 -- curl -s http://backend-service:4000/api | grep status
|
@ -1,83 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# Create a ConfigMap with route patches for the backend
|
||||
cat > /tmp/route-patches.js << 'EOF'
|
||||
// Root route
|
||||
app.get('/', (req, res) => {
|
||||
res.json({ message: 'Welcome to the API' });
|
||||
});
|
||||
|
||||
// Health check endpoint
|
||||
app.get('/api', (req, res) => {
|
||||
res.json({ status: 'ok', message: 'API is healthy' });
|
||||
});
|
||||
|
||||
// Update existing routes if needed
|
||||
app.get('/api/health', (req, res) => {
|
||||
res.json({ status: 'ok' });
|
||||
});
|
||||
EOF
|
||||
|
||||
kubectl create configmap route-patches -n sk1 --from-file=routes.js=/tmp/route-patches.js --dry-run=client -o yaml | kubectl apply -f -
|
||||
|
||||
# Create a strategic merge patch that only modifies what we need
|
||||
cat > /tmp/backend-patch-routes.yaml << EOF
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: backend
|
||||
namespace: sk1
|
||||
spec:
|
||||
template:
|
||||
spec:
|
||||
containers:
|
||||
- name: backend
|
||||
env:
|
||||
- name: DEBUG
|
||||
value: "express:*"
|
||||
volumeMounts:
|
||||
- name: route-patches
|
||||
mountPath: /routes
|
||||
volumes:
|
||||
- name: route-patches
|
||||
configMap:
|
||||
name: route-patches
|
||||
EOF
|
||||
|
||||
# Apply the patch with strategic merge patch type
|
||||
kubectl patch deployment backend -n sk1 --patch-file /tmp/backend-patch-routes.yaml --type=strategic
|
||||
|
||||
# Create a script to apply routes to the running container
|
||||
cat > /tmp/apply-routes.sh << 'EOF'
|
||||
#!/bin/bash
|
||||
# Get the backend pod name
|
||||
BACKEND_POD=$(kubectl get pods -n sk1 -l app=backend -o jsonpath='{.items[0].metadata.name}')
|
||||
|
||||
# Copy the routes file to the pod
|
||||
echo "Copying routes to pod $BACKEND_POD..."
|
||||
kubectl exec -n sk1 $BACKEND_POD -- mkdir -p /tmp/routes
|
||||
kubectl cp /tmp/route-patches.js $BACKEND_POD:/tmp/routes/routes.js -n sk1
|
||||
|
||||
# Apply routes to the running application
|
||||
echo "Applying routes..."
|
||||
kubectl exec -n sk1 $BACKEND_POD -- sh -c '
|
||||
echo "// Added routes:" >> /app/index.js
|
||||
cat /tmp/routes/routes.js >> /app/index.js
|
||||
echo "Routes added to index.js"
|
||||
# Try to send SIGHUP to process 1 to reload
|
||||
if kill -SIGHUP 1; then
|
||||
echo "Sent SIGHUP to main process"
|
||||
else
|
||||
echo "Could not send SIGHUP, will restart pod"
|
||||
exit 1
|
||||
fi
|
||||
'
|
||||
EOF
|
||||
|
||||
chmod +x /tmp/apply-routes.sh
|
||||
/tmp/apply-routes.sh || kubectl rollout restart deployment backend -n sk1
|
||||
|
||||
echo "Added missing API routes to backend"
|
||||
echo "Waiting for backend to restart..."
|
||||
kubectl rollout status deployment backend -n sk1
|
@ -1,44 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# Create a backend deployment patch with better configuration
|
||||
cat > /tmp/backend-patch.yaml << EOF
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: backend
|
||||
namespace: sk1
|
||||
spec:
|
||||
template:
|
||||
spec:
|
||||
containers:
|
||||
- name: backend
|
||||
env:
|
||||
- name: PORT
|
||||
value: "4000"
|
||||
- name: HOST
|
||||
value: "0.0.0.0"
|
||||
# Remove existing probes first
|
||||
readinessProbe:
|
||||
httpGet:
|
||||
path: /api
|
||||
port: 4000
|
||||
initialDelaySeconds: 30
|
||||
periodSeconds: 15
|
||||
timeoutSeconds: 5
|
||||
livenessProbe:
|
||||
httpGet:
|
||||
path: /api
|
||||
port: 4000
|
||||
initialDelaySeconds: 45
|
||||
periodSeconds: 20
|
||||
timeoutSeconds: 5
|
||||
EOF
|
||||
|
||||
# Apply the patch
|
||||
kubectl patch deployment backend -n sk1 --patch-file /tmp/backend-patch.yaml
|
||||
|
||||
# Restart backend pods to apply changes
|
||||
kubectl rollout restart deployment backend -n sk1
|
||||
|
||||
echo "Backend deployment patched with improved health checks"
|
@ -1,33 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# Get information about our running pods
|
||||
RUNNING_POD=$(kubectl get pods -n sk1 -l app=backend --field-selector=status.phase=Running -o jsonpath='{.items[0].metadata.name}')
|
||||
RUNNING_IP=$(kubectl get pod $RUNNING_POD -n sk1 -o jsonpath='{.status.podIP}')
|
||||
|
||||
echo "Running pod: $RUNNING_POD with IP: $RUNNING_IP"
|
||||
|
||||
# Update the backend service to explicitly include our running pod
|
||||
cat > /tmp/fixed-backend-service.yaml << EOF
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: backend-service
|
||||
namespace: sk1
|
||||
spec:
|
||||
ports:
|
||||
- port: 4000
|
||||
targetPort: 4000
|
||||
selector:
|
||||
app: backend
|
||||
EOF
|
||||
|
||||
# Apply the fixed service
|
||||
kubectl apply -f /tmp/fixed-backend-service.yaml
|
||||
|
||||
# Force endpoints to update by restarting the backend pod
|
||||
kubectl rollout restart deployment backend -n sk1
|
||||
|
||||
echo "Backend service updated, checking endpoints..."
|
||||
sleep 5
|
||||
kubectl get endpoints backend-service -n sk1
|
@ -1,27 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# Get project ID
|
||||
PROJECT=$(gcloud config get-value project)
|
||||
echo "Using project: ${PROJECT}"
|
||||
|
||||
# Show current images in registry
|
||||
echo "Checking available images:"
|
||||
gcloud container images list --repository=gcr.io/${PROJECT}
|
||||
|
||||
# Create deployment files with correct project ID
|
||||
echo "Creating deployment files with project ID ${PROJECT}"
|
||||
sed "s|\${PROJECT}|${PROJECT}|g" k8s/backend-deployment.yml.tpl > /tmp/backend-deployment.yml
|
||||
sed "s|\${PROJECT}|${PROJECT}|g" k8s/frontend-deployment.yml.tpl > /tmp/frontend-deployment.yml
|
||||
|
||||
# Show what images will be used
|
||||
echo "Backend image: $(grep "image:" /tmp/backend-deployment.yml)"
|
||||
echo "Frontend image: $(grep "image:" /tmp/frontend-deployment.yml)"
|
||||
|
||||
# Apply fixed deployments
|
||||
kubectl apply -n sk1 -f /tmp/backend-deployment.yml
|
||||
kubectl apply -n sk1 -f /tmp/frontend-deployment.yml
|
||||
|
||||
# Watch pods come up
|
||||
echo "Watching pods..."
|
||||
kubectl get pods -n sk1 -w
|
@ -1,58 +0,0 @@
|
||||
#!/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
|
@ -1,67 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# Create a final nginx config for frontend
|
||||
cat > /tmp/final-nginx.conf << 'EOF'
|
||||
server {
|
||||
listen 80;
|
||||
server_name localhost;
|
||||
root /usr/share/nginx/html;
|
||||
index index.html;
|
||||
|
||||
# API requests - make sure to point to the backend-service
|
||||
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;
|
||||
}
|
||||
|
||||
# All other requests go to the React app
|
||||
location / {
|
||||
try_files $uri $uri/ /index.html;
|
||||
}
|
||||
}
|
||||
EOF
|
||||
|
||||
# Create a ConfigMap from this nginx config
|
||||
kubectl create configmap final-nginx-conf -n sk1 --from-file=nginx.conf=/tmp/final-nginx.conf --dry-run=client -o yaml | kubectl apply -f -
|
||||
|
||||
# Use patch command instead of apply
|
||||
kubectl patch deployment frontend -n sk1 --type=strategic --patch '
|
||||
{
|
||||
"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": "final-nginx-conf"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
'
|
||||
|
||||
# Restart frontend pods
|
||||
kubectl rollout restart deployment frontend -n sk1
|
||||
|
||||
echo "✅ Frontend nginx configuration updated"
|
@ -1,53 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
echo "🔍 Checking ingress configuration..."
|
||||
kubectl get ingress -n sk1
|
||||
|
||||
# Update the ingress to ensure proper backend routing
|
||||
cat > /tmp/ingress-patch.yaml << EOF
|
||||
spec:
|
||||
rules:
|
||||
- host: nudges.works
|
||||
http:
|
||||
paths:
|
||||
- path: /
|
||||
pathType: Prefix
|
||||
backend:
|
||||
service:
|
||||
name: frontend-service
|
||||
port:
|
||||
number: 80
|
||||
- path: /api
|
||||
pathType: Prefix
|
||||
backend:
|
||||
service:
|
||||
name: backend-service
|
||||
port:
|
||||
number: 4000
|
||||
EOF
|
||||
|
||||
echo "📝 Patching ingress configuration..."
|
||||
INGRESS_NAME=$(kubectl get ingress -n sk1 -o jsonpath='{.items[0].metadata.name}')
|
||||
kubectl patch ingress $INGRESS_NAME -n sk1 --patch-file /tmp/ingress-patch.yaml
|
||||
|
||||
echo "🔄 Restarting frontend to ensure clean configuration..."
|
||||
kubectl rollout restart deployment frontend -n sk1
|
||||
|
||||
echo "⏱️ Waiting for frontend to restart..."
|
||||
kubectl rollout status deployment frontend -n sk1
|
||||
|
||||
echo "✅ Configuration updated!"
|
||||
echo ""
|
||||
echo "Try accessing your app at https://nudges.works now."
|
||||
echo "Please clear your browser cache or use an incognito window."
|
||||
|
||||
echo "👉 You can also try these direct links to verify functionality:"
|
||||
echo " - https://nudges.works/api/services/assembly"
|
||||
echo " - https://nudges.works/api/health"
|
||||
echo ""
|
||||
echo "If you're still having issues, try the direct IP address:"
|
||||
IP=$(kubectl get svc frontend-service -n sk1 -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
|
||||
if [ -n "$IP" ]; then
|
||||
echo " - http://$IP/api/services/assembly"
|
||||
fi
|
@ -1,45 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# Create a temporary pod to examine the frontend code
|
||||
kubectl run debug-react -n sk1 --image=busybox -- sleep 3600
|
||||
|
||||
# Wait for pod to be ready
|
||||
kubectl wait --for=condition=Ready pod/debug-react -n sk1 --timeout=60s
|
||||
|
||||
# Create a config.js file with the correct API URL
|
||||
cat > /tmp/config.js << EOF
|
||||
// API Configuration
|
||||
window.API_URL = '/api'; // Use relative path for API calls
|
||||
console.log('API configuration loaded');
|
||||
EOF
|
||||
|
||||
# Copy this file to the frontend pod's HTML directory
|
||||
kubectl cp /tmp/config.js debug-react:/tmp/config.js -n sk1
|
||||
|
||||
# Find all frontend pods
|
||||
FRONTEND_PODS=$(kubectl get pods -n sk1 -l app=frontend -o jsonpath='{.items[*].metadata.name}')
|
||||
|
||||
# Copy the config to each frontend pod
|
||||
for pod in $FRONTEND_PODS; do
|
||||
echo "Updating config in pod $pod..."
|
||||
kubectl cp /tmp/config.js $pod:/usr/share/nginx/html/config.js -n sk1
|
||||
|
||||
# Verify the file was copied
|
||||
kubectl exec $pod -n sk1 -- ls -la /usr/share/nginx/html/config.js || echo "Failed to copy config.js to $pod"
|
||||
done
|
||||
|
||||
# Update index.html to include this config file
|
||||
for pod in $FRONTEND_PODS; do
|
||||
kubectl exec $pod -n sk1 -- sh -c '
|
||||
if grep -q config.js /usr/share/nginx/html/index.html; then
|
||||
echo "Config already included in index.html"
|
||||
else
|
||||
echo "Adding config.js to index.html"
|
||||
sed -i "s|<head>|<head>\n <script src=\"/config.js\"></script>|" /usr/share/nginx/html/index.html
|
||||
fi
|
||||
'
|
||||
done
|
||||
|
||||
echo "✅ Frontend configuration updated with correct API URL"
|
||||
echo "Try accessing your application again at https://nudges.works"
|
@ -1,130 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# Create a more complete service routes file
|
||||
cat > /tmp/service-routes.js << 'EOF'
|
||||
// Service routes
|
||||
app.get('/api/services/assembly', (req, res) => {
|
||||
// Extract query parameters
|
||||
const { radius, page, sortBy, order, lat, lon } = req.query;
|
||||
|
||||
// Return mock data for now
|
||||
res.json({
|
||||
success: true,
|
||||
services: [
|
||||
{
|
||||
id: 1,
|
||||
name: "Assembly Service 1",
|
||||
description: "Professional furniture assembly",
|
||||
price: 25,
|
||||
distance: 2.5,
|
||||
rating: 4.5
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
name: "Assembly Service 2",
|
||||
description: "IKEA specialist",
|
||||
price: 30,
|
||||
distance: 3.2,
|
||||
rating: 4.8
|
||||
}
|
||||
],
|
||||
pagination: {
|
||||
currentPage: parseInt(page) || 1,
|
||||
totalPages: 3,
|
||||
totalResults: 6
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Add other service routes
|
||||
app.get('/api/services/:serviceType', (req, res) => {
|
||||
const serviceType = req.params.serviceType;
|
||||
const { radius, page, sortBy, order, lat, lon } = req.query;
|
||||
|
||||
// Return mock data for any service type
|
||||
res.json({
|
||||
success: true,
|
||||
services: [
|
||||
{
|
||||
id: 1,
|
||||
name: `${serviceType} Service 1`,
|
||||
description: `Professional ${serviceType} service`,
|
||||
price: Math.floor(Math.random() * 50) + 20,
|
||||
distance: parseFloat((Math.random() * 5).toFixed(1)),
|
||||
rating: parseFloat((Math.random() * 2 + 3).toFixed(1))
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
name: `${serviceType} Service 2`,
|
||||
description: `Expert ${serviceType} provider`,
|
||||
price: Math.floor(Math.random() * 50) + 20,
|
||||
distance: parseFloat((Math.random() * 5).toFixed(1)),
|
||||
rating: parseFloat((Math.random() * 2 + 3).toFixed(1))
|
||||
}
|
||||
],
|
||||
pagination: {
|
||||
currentPage: parseInt(page) || 1,
|
||||
totalPages: 3,
|
||||
totalResults: 6
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Authentication endpoints
|
||||
app.post('/api/auth/login', (req, res) => {
|
||||
res.json({
|
||||
success: true,
|
||||
token: "mock-jwt-token",
|
||||
user: {
|
||||
id: 1,
|
||||
name: "Test User",
|
||||
email: "test@example.com"
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
app.post('/api/auth/register', (req, res) => {
|
||||
res.json({
|
||||
success: true,
|
||||
message: "User registered successfully"
|
||||
});
|
||||
});
|
||||
EOF
|
||||
|
||||
# Create a ConfigMap with these routes
|
||||
kubectl create configmap service-routes -n sk1 --from-file=routes.js=/tmp/service-routes.js --dry-run=client -o yaml | kubectl apply -f -
|
||||
|
||||
# Find the backend pod
|
||||
BACKEND_POD=$(kubectl get pods -n sk1 -l app=backend-fixed -o jsonpath='{.items[0].metadata.name}')
|
||||
|
||||
# Copy the routes file to the backend pod
|
||||
kubectl cp /tmp/service-routes.js $BACKEND_POD:/tmp/routes.js -n sk1
|
||||
|
||||
# Apply these routes to the running backend
|
||||
kubectl exec $BACKEND_POD -n sk1 -- sh -c '
|
||||
echo "// Adding service routes" >> /app/index.js
|
||||
cat /tmp/routes.js >> /app/index.js
|
||||
echo "Service routes added to backend"
|
||||
|
||||
# Force Node.js to reload (not ideal, but works for demo)
|
||||
# In production, you would rebuild the container
|
||||
kill -SIGHUP 1 || echo "Could not send SIGHUP, will restart pod instead"
|
||||
'
|
||||
|
||||
# Restart the backend pod to ensure routes are loaded
|
||||
kubectl rollout restart deployment backend-fixed -n sk1
|
||||
|
||||
echo "✅ Added service routes to backend"
|
||||
echo "Waiting for backend to restart..."
|
||||
kubectl rollout status deployment backend-fixed -n sk1
|
||||
|
||||
echo "🔍 Testing the specific route that was failing..."
|
||||
# Create a test pod to check the route
|
||||
kubectl run test-route --image=curlimages/curl -n sk1 --rm -it -- sh -c '
|
||||
echo "Testing /api/services/assembly endpoint:"
|
||||
curl -s "http://backend-service:4000/api/services/assembly?radius=10&page=1&sortBy=distance&order=asc"
|
||||
echo ""
|
||||
'
|
||||
|
||||
echo "✨ Routes should now be working. Try accessing your application again at https://nudges.works"
|
@ -1,29 +0,0 @@
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: fixed-nginx-conf
|
||||
namespace: sk1
|
||||
data:
|
||||
nginx.conf: |
|
||||
server {
|
||||
listen 80;
|
||||
server_name localhost;
|
||||
root /usr/share/nginx/html;
|
||||
index index.html;
|
||||
|
||||
# All API requests should go to backend service
|
||||
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_set_header X-Real-IP $remote_addr;
|
||||
proxy_cache_bypass $http_upgrade;
|
||||
}
|
||||
|
||||
# All other requests go to the React app
|
||||
location / {
|
||||
try_files $uri $uri/ /index.html;
|
||||
}
|
||||
}
|
@ -1,78 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# Get project ID
|
||||
PROJECT=$(gcloud config get-value project)
|
||||
|
||||
# Create a new fixed backend deployment
|
||||
cat > /tmp/fixed-backend.yaml << EOF
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: backend
|
||||
namespace: sk1
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: backend
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: backend
|
||||
spec:
|
||||
containers:
|
||||
- name: backend
|
||||
image: gcr.io/${PROJECT}/backend:latest
|
||||
resources:
|
||||
limits:
|
||||
cpu: "0.5"
|
||||
memory: "512Mi"
|
||||
requests:
|
||||
cpu: "0.2"
|
||||
memory: "256Mi"
|
||||
ports:
|
||||
- containerPort: 4000
|
||||
env:
|
||||
- name: PORT
|
||||
value: "4000"
|
||||
- name: HOST
|
||||
value: "0.0.0.0"
|
||||
- name: MONGO_URI
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: mongodb-secret
|
||||
key: MONGO_URI
|
||||
- name: JWT_SECRET
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: mongodb-secret
|
||||
key: JWT_SECRET
|
||||
- name: GOOGLE_PLACES_API_KEY
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: mongodb-secret
|
||||
key: GOOGLE_PLACES_API_KEY
|
||||
# Simple health check that should work
|
||||
readinessProbe:
|
||||
httpGet:
|
||||
path: /api
|
||||
port: 4000
|
||||
initialDelaySeconds: 30
|
||||
periodSeconds: 5
|
||||
timeoutSeconds: 2
|
||||
livenessProbe:
|
||||
httpGet:
|
||||
path: /api
|
||||
port: 4000
|
||||
initialDelaySeconds: 60
|
||||
periodSeconds: 15
|
||||
timeoutSeconds: 2
|
||||
EOF
|
||||
|
||||
# Apply the new deployment
|
||||
kubectl apply -f /tmp/fixed-backend.yaml
|
||||
|
||||
echo "Applied fixed backend deployment"
|
||||
echo "Watching backend pods..."
|
||||
kubectl get pods -n sk1 -l app=backend -w
|
@ -1,18 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# Get project ID and zone
|
||||
PROJECT=$(gcloud config get-value project)
|
||||
ZONE="us-central1-a"
|
||||
CLUSTER="sk1-cluster"
|
||||
|
||||
echo "🔄 Refreshing connection to GKE cluster..."
|
||||
gcloud container clusters get-credentials ${CLUSTER} --zone ${ZONE} --project ${PROJECT}
|
||||
|
||||
echo "✅ Connection refreshed"
|
||||
|
||||
# Check what resources exist
|
||||
echo "🔍 Checking resources..."
|
||||
kubectl get pods -n sk1
|
||||
kubectl get services -n sk1
|
||||
kubectl get ingress -n sk1 || echo "No ingress resources found"
|
@ -1,96 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# Get project ID
|
||||
PROJECT=$(gcloud config get-value project)
|
||||
ZONE="us-central1-a"
|
||||
CLUSTER="sk1-cluster"
|
||||
|
||||
echo "🔄 Refreshing connection to GKE cluster..."
|
||||
for i in {1..5}; do
|
||||
echo "Attempt $i to connect to cluster..."
|
||||
if gcloud container clusters get-credentials ${CLUSTER} --zone ${ZONE} --project ${PROJECT}; then
|
||||
echo "✅ Connection successful!"
|
||||
break
|
||||
else
|
||||
echo "❌ Connection failed, retrying in 5 seconds..."
|
||||
sleep 5
|
||||
fi
|
||||
|
||||
# If we've tried 5 times and still can't connect, show the cluster status
|
||||
if [ $i -eq 5 ]; then
|
||||
echo "⚠️ Unable to connect after 5 attempts. Checking cluster status..."
|
||||
gcloud container clusters describe ${CLUSTER} --zone ${ZONE} --project ${PROJECT}
|
||||
fi
|
||||
done
|
||||
|
||||
echo "📝 Saving deployment YAML files locally..."
|
||||
|
||||
# Save the deployment YAML locally
|
||||
cat > backend-fixed-deployment.yaml << EOF
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: backend-fixed
|
||||
namespace: sk1
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: backend-fixed
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: backend-fixed
|
||||
spec:
|
||||
containers:
|
||||
- name: backend
|
||||
image: gcr.io/${PROJECT}/backend-fixed:latest
|
||||
env:
|
||||
- name: PORT
|
||||
value: "4000"
|
||||
- name: HOST
|
||||
value: "0.0.0.0"
|
||||
- name: MONGO_URI
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: mongodb-secret
|
||||
key: MONGO_URI
|
||||
ports:
|
||||
- containerPort: 4000
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: backend-service
|
||||
namespace: sk1
|
||||
spec:
|
||||
selector:
|
||||
app: backend-fixed
|
||||
ports:
|
||||
- port: 4000
|
||||
targetPort: 4000
|
||||
EOF
|
||||
|
||||
echo "🚀 Attempting to apply deployment YAML..."
|
||||
for i in {1..5}; do
|
||||
echo "Attempt $i to apply deployment..."
|
||||
if kubectl apply -f backend-fixed-deployment.yaml; then
|
||||
echo "✅ Deployment successful!"
|
||||
break
|
||||
else
|
||||
echo "❌ Deployment failed, retrying in 5 seconds..."
|
||||
sleep 5
|
||||
fi
|
||||
done
|
||||
|
||||
echo "🌐 Testing connection to GKE ingress..."
|
||||
IP=$(gcloud compute addresses describe sk1-static-ip --global --format="value(address)")
|
||||
echo "Your static IP is: ${IP}"
|
||||
|
||||
echo "✨ Next steps:"
|
||||
echo "1. Access your application at: https://nudges.works"
|
||||
echo "2. If issues persist, try accessing the backend directly:"
|
||||
echo " curl -v http://${IP}/api"
|
||||
echo "3. You can also check the GCP Console for more details:"
|
||||
echo " https://console.cloud.google.com/kubernetes/workload"
|
@ -1,66 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# Get project ID
|
||||
PROJECT=$(gcloud config get-value project)
|
||||
|
||||
# Create a new fixed backend deployment with NO health probes
|
||||
cat > /tmp/basic-backend.yaml << EOF
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: backend
|
||||
namespace: sk1
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: backend
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: backend
|
||||
spec:
|
||||
containers:
|
||||
- name: backend
|
||||
image: gcr.io/${PROJECT}/backend:latest
|
||||
resources:
|
||||
limits:
|
||||
cpu: "0.5"
|
||||
memory: "512Mi"
|
||||
requests:
|
||||
cpu: "0.2"
|
||||
memory: "256Mi"
|
||||
ports:
|
||||
- containerPort: 4000
|
||||
env:
|
||||
- name: PORT
|
||||
value: "4000"
|
||||
- name: HOST
|
||||
value: "0.0.0.0"
|
||||
- name: MONGO_URI
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: mongodb-secret
|
||||
key: MONGO_URI
|
||||
- name: JWT_SECRET
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: mongodb-secret
|
||||
key: JWT_SECRET
|
||||
- name: GOOGLE_PLACES_API_KEY
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: mongodb-secret
|
||||
key: GOOGLE_PLACES_API_KEY
|
||||
# Add more verbose logging
|
||||
- name: DEBUG
|
||||
value: "express:*"
|
||||
EOF
|
||||
|
||||
# Apply the new deployment
|
||||
kubectl apply -f /tmp/basic-backend.yaml
|
||||
|
||||
echo "Applied basic backend deployment without health probes"
|
||||
echo "Watching backend pods..."
|
||||
kubectl get pods -n sk1 -l app=backend -w
|
@ -1,27 +0,0 @@
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: Ingress
|
||||
metadata:
|
||||
name: sk1-ingress
|
||||
namespace: sk1
|
||||
annotations:
|
||||
kubernetes.io/ingress.global-static-ip-name: sk1-static-ip
|
||||
networking.gke.io/managed-certificates: sk1-cert
|
||||
spec:
|
||||
rules:
|
||||
- host: nudges.works
|
||||
http:
|
||||
paths:
|
||||
- path: /api
|
||||
pathType: Prefix
|
||||
backend:
|
||||
service:
|
||||
name: backend-service
|
||||
port:
|
||||
number: 4000
|
||||
- path: /
|
||||
pathType: Prefix
|
||||
backend:
|
||||
service:
|
||||
name: frontend-service
|
||||
port:
|
||||
number: 80
|
@ -1,15 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# Test backend API endpoints
|
||||
kubectl run api-test --image=curlimages/curl -n sk1 --rm -it -- sh -c '
|
||||
echo "Testing backend API endpoints..."
|
||||
echo "1. Root endpoint:"
|
||||
curl -v http://backend-service:4000/ 2>&1 | grep "< HTTP"
|
||||
echo ""
|
||||
echo "2. /api endpoint:"
|
||||
curl -v http://backend-service:4000/api 2>&1 | grep "< HTTP"
|
||||
echo ""
|
||||
echo "3. /api/auth/login endpoint:"
|
||||
curl -v http://backend-service:4000/api/auth/login 2>&1 | grep "< HTTP"
|
||||
'
|
@ -1,12 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# Create a debug pod to test backend API
|
||||
kubectl run debug-pod --image=curlimages/curl -n sk1 --rm -it -- sh -c '
|
||||
echo "Testing backend API..."
|
||||
echo "1. Testing /api endpoint:"
|
||||
curl -v http://backend-service:4000/api
|
||||
echo ""
|
||||
echo "2. Testing /api/auth/login endpoint:"
|
||||
curl -v http://backend-service:4000/api/auth/login
|
||||
'
|
@ -1,9 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# Create a test pod in the same namespace
|
||||
kubectl run curl-basic --image=curlimages/curl -n sk1 --rm -it -- sh -c '
|
||||
echo "Simple connection test to backend-service:4000..."
|
||||
curl -v telnet://backend-service:4000 2>&1 | grep "Connected"
|
||||
echo ""
|
||||
'
|
@ -1,38 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# Create a netshoot pod for better networking diagnostics
|
||||
cat > /tmp/netshoot.yaml << EOF
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: netshoot
|
||||
namespace: sk1
|
||||
spec:
|
||||
containers:
|
||||
- name: netshoot
|
||||
image: nicolaka/netshoot
|
||||
command:
|
||||
- sleep
|
||||
- "3600"
|
||||
EOF
|
||||
|
||||
kubectl apply -f /tmp/netshoot.yaml
|
||||
|
||||
# Wait for pod to be ready
|
||||
echo "Waiting for netshoot pod to be ready..."
|
||||
kubectl wait --for=condition=Ready pod/netshoot -n sk1 --timeout=60s
|
||||
|
||||
# Test DNS resolution and connectivity
|
||||
kubectl exec -it netshoot -n sk1 -- bash -c '
|
||||
echo "Checking DNS for backend-service..."
|
||||
nslookup backend-service
|
||||
echo ""
|
||||
|
||||
echo "Checking port connectivity..."
|
||||
nc -zv backend-service 4000
|
||||
echo ""
|
||||
|
||||
echo "Trying HTTP request to backend service..."
|
||||
curl -v http://backend-service:4000/
|
||||
'
|
@ -1,12 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# Create a temporary pod to check what routes are available
|
||||
kubectl run curl-test --image=curlimages/curl -n sk1 --rm -it -- sh -c '
|
||||
echo "Testing backend routes..."
|
||||
for endpoint in / /api /api/ /api/health /healthz; do
|
||||
echo "Testing $endpoint:"
|
||||
curl -s -o /dev/null -w "%{http_code}" http://backend-service:4000$endpoint
|
||||
echo ""
|
||||
done
|
||||
'
|
@ -1,60 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# Create a final nginx config for frontend
|
||||
cat > /tmp/final-nginx.conf << 'EOF'
|
||||
server {
|
||||
listen 80;
|
||||
server_name localhost;
|
||||
root /usr/share/nginx/html;
|
||||
index index.html;
|
||||
|
||||
# API requests - make sure to point to the backend-service
|
||||
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;
|
||||
}
|
||||
|
||||
# All other requests go to the React app
|
||||
location / {
|
||||
try_files $uri $uri/ /index.html;
|
||||
}
|
||||
}
|
||||
EOF
|
||||
|
||||
# Create a ConfigMap from this nginx config
|
||||
kubectl create configmap final-nginx-conf -n sk1 --from-file=nginx.conf=/tmp/final-nginx.conf --dry-run=client -o yaml | kubectl apply -f -
|
||||
|
||||
# Update frontend deployment to use this ConfigMap
|
||||
cat > /tmp/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: final-nginx-conf
|
||||
EOF
|
||||
|
||||
# Apply the update
|
||||
kubectl apply -f /tmp/frontend-update.yaml
|
||||
|
||||
# Restart frontend pods
|
||||
kubectl rollout restart deployment frontend -n sk1
|
||||
|
||||
echo "✅ Frontend nginx configuration updated"
|
@ -1,59 +0,0 @@
|
||||
#!/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
|
@ -1,21 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
echo "🔍 Checking pods..."
|
||||
kubectl get pods -n sk1
|
||||
|
||||
echo "🔍 Checking services..."
|
||||
kubectl get services -n sk1
|
||||
|
||||
echo "🔍 Checking backend logs..."
|
||||
BACKEND_POD=$(kubectl get pods -n sk1 -l app=backend -o jsonpath='{.items[0].metadata.name}' 2>/dev/null) || echo "No backend pod found"
|
||||
if [ -n "$BACKEND_POD" ]; then
|
||||
kubectl logs -n sk1 $BACKEND_POD --tail=10
|
||||
else
|
||||
echo "⚠️ Backend pod not found. Please check deployment status."
|
||||
fi
|
||||
|
||||
echo "🔍 Testing backend service directly..."
|
||||
kubectl run test-backend --image=curlimages/curl -n sk1 --rm -it -- curl -v http://backend-service:4000/api || echo "Failed to test backend"
|
||||
|
||||
echo "✅ Verification complete!"
|
Loading…
Reference in New Issue
Block a user