Files

159 lines
5.2 KiB
Bash
Executable File

#!/bin/bash
# Verification script for nginx-load-balancer fixes
# Tests the applied configuration changes
set -e
echo "🔍 nginx-load-balancer Fix Verification"
echo "======================================"
echo ""
# Colors
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
RED='\033[0;31m'
NC='\033[0m' # No Color
echo "🔍 Checking if fixes were applied..."
echo ""
# Check 1: Verify current pods distribution
echo "📍 Step 1: Checking pod distribution..."
PODS=$(kubectl get pods -l app=nginx-load-balancer -o wide)
if echo "$PODS" | grep -q "master"; then
echo -e "${RED}❌ ISSUE: Pods found on master nodes (node affinity fix not working)${NC}"
echo "$PODS"
else
echo -e "${GREEN}✅ GOOD: No pods on master nodes (node affinity working)${NC}"
fi
echo "$PODS"
echo ""
# Check 2: Count pods per node type
echo "📊 Step 2: Analyzing pod distribution by node type..."
WORKER_PODS=$(echo "$PODS" | grep -v "master" | grep -v "NAME" | wc -l)
TOTAL_PODS=$(echo "$PODS" | grep -v "NAME" | wc -l)
echo "Total pods running: $TOTAL_PODS"
echo "Pods on worker nodes: $WORKER_PODS"
if [ "$WORKER_PODS" -eq 3 ] && [ "$TOTAL_PODS" -eq 3 ]; then
echo -e "${GREEN}✅ EXPECTED: 3 pods on 3 worker nodes only${NC}"
else
echo -e "${YELLOW}⚠️ UNEXPECTED: Expected 3 pods on 3 worker nodes${NC}"
fi
echo ""
# Check 3: Service configuration
echo "🔧 Step 3: Checking service configuration..."
SERVICE=$(kubectl get svc nginx-load-balancer-service -o yaml)
if echo "$SERVICE" | grep -q "externalTrafficPolicy: Local"; then
echo -e "${RED}❌ ISSUE: externalTrafficPolicy: Local still present${NC}"
echo " This may cause LoadBalancer IP issues"
else
echo -e "${GREEN}✅ GOOD: externalTrafficPolicy: Local removed${NC}"
fi
if echo "$SERVICE" | grep -q "type: LoadBalancer"; then
echo -e "${GREEN}✅ GOOD: Service type is LoadBalancer${NC}"
else
echo -e "${RED}❌ ISSUE: Service type is not LoadBalancer${NC}"
fi
echo ""
# Check 4: LoadBalancer IP availability
echo "🌐 Step 4: Checking LoadBalancer IP..."
SERVICE_STATUS=$(kubectl get svc nginx-load-balancer-service -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
SERVICE_PORT=$(kubectl get svc nginx-load-balancer-service -o jsonpath='{.spec.ports[0].port}')
if [ -n "$SERVICE_STATUS" ]; then
echo -e "${GREEN}✅ GOOD: LoadBalancer IP assigned: $SERVICE_STATUS${NC}"
echo " Full URL: http://$SERVICE_STATUS:$SERVICE_PORT"
# Test LoadBalancer IP
echo ""
echo "🧪 Testing LoadBalancer IP access..."
if timeout 10 curl -s -f "http://$SERVICE_STATUS:$SERVICE_PORT" > /dev/null 2>&1; then
echo -e "${GREEN}✅ GOOD: LoadBalancer IP is accessible${NC}"
else
echo -e "${RED}❌ ISSUE: LoadBalancer IP is not accessible${NC}"
echo " Try: curl -6 'http://[$SERVICE_STATUS]:$SERVICE_PORT'"
fi
else
echo -e "${YELLOW}⚠️ WAITING: LoadBalancer IP not yet assigned${NC}"
fi
echo ""
# Check 5: Node access (dual access pattern)
echo "🔗 Step 5: Testing dual access pattern..."
# Get a node IP for testing
NODE_IPS=$(kubectl get nodes -o jsonpath='{range .items[*]}{.status.addresses[?@.type=="InternalIP"].address}{"\n"}{end}' | head -3)
WORKER_COUNT=0
for node_ip in $NODE_IPS; do
echo "Testing node: $node_ip"
# Test direct node access
if timeout 5 curl -s -f "http://$node_ip:8080" > /dev/null 2>&1; then
echo -e "${GREEN} ✅ Direct node access works${NC}"
WORKER_COUNT=$((WORKER_COUNT + 1))
else
echo -e "${YELLOW} ⚠️ Direct node access failed${NC}"
fi
done
echo "Nodes with working direct access: $WORKER_COUNT"
echo ""
# Check 6: Deployment configuration
echo "⚙️ Step 6: Checking deployment configuration..."
DEPLOYMENT=$(kubectl get deployment nginx-load-balancer -o yaml)
if echo "$DEPLOYMENT" | grep -q "requiredDuringSchedulingIgnoredDuringExecution"; then
echo -e "${GREEN}✅ GOOD: Hard node affinity configured${NC}"
else
echo -e "${RED}❌ ISSUE: Hard node affinity not found${NC}"
fi
if echo "$DEPLOYMENT" | grep -q "node-role.kubernetes.io/master"; then
echo -e "${GREEN}✅ GOOD: Node role filtering configured${NC}"
else
echo -e "${YELLOW}⚠️ WARNING: Node role filtering may be missing${NC}"
fi
echo ""
# Summary
echo "======================================"
echo "📊 VERIFICATION SUMMARY"
echo "======================================"
echo ""
if echo "$PODS" | grep -q "master"; then
echo -e "${RED}❌ NODE AFFINITY: Pods on master nodes (need fix)${NC}"
else
echo -e "${GREEN}✅ NODE AFFINITY: Pods on worker nodes only${NC}"
fi
if [ -n "$SERVICE_STATUS" ]; then
echo -e "${GREEN}✅ LOADBALANCER: IP assigned ($SERVICE_STATUS)${NC}"
else
echo -e "${YELLOW}⚠️ LOADBALANCER: IP not assigned yet${NC}"
fi
echo -e "${BLUE}🎯 DUAL ACCESS: Both LoadBalancer IP and node access should work${NC}"
echo ""
echo "🔧 Next steps if issues found:"
echo "1. Apply fixes: kubectl apply -f nginx-load-balancer-deployment.yaml"
echo "2. Apply service: kubectl apply -f nginx-load-balancer-service.yaml"
echo "3. Restart deployment: kubectl rollout restart deployment/nginx-load-balancer"
echo "4. Re-run this verification script"
echo ""
echo "✅ Verification complete!"