177 lines
6.2 KiB
Bash
Executable File
177 lines
6.2 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Complete Deploy and Test Script for nginx-nodeport
|
|
# This script does EVERYTHING from scratch in the correct order
|
|
|
|
set -e
|
|
|
|
echo "🚀 nginx-nodeport Deploy and Test"
|
|
echo "=================================="
|
|
echo ""
|
|
|
|
# Colors
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
BLUE='\033[0;34m'
|
|
NC='\033[0m' # No Color
|
|
|
|
# Step 1: Check if kubectl is available
|
|
echo "🔍 Step 1: Checking prerequisites..."
|
|
if ! command -v kubectl &> /dev/null; then
|
|
echo "❌ kubectl is not installed or not in PATH"
|
|
echo " Please install kubectl and configure it to connect to your Mycelium Cloud cluster"
|
|
exit 1
|
|
fi
|
|
|
|
# Test cluster connectivity
|
|
if ! kubectl cluster-info &> /dev/null; then
|
|
echo "❌ Cannot connect to Kubernetes cluster"
|
|
echo " Please check your kubeconfig configuration"
|
|
exit 1
|
|
fi
|
|
|
|
echo -e "${GREEN}✅ kubectl is available and connected to cluster${NC}"
|
|
echo ""
|
|
|
|
# Step 2: Deploy all resources
|
|
echo "🔍 Step 2: Deploying nginx-nodeport resources..."
|
|
echo ""
|
|
|
|
echo " 📦 Deploying ConfigMaps..."
|
|
kubectl apply -f nginx-nodeport-configmaps.yaml
|
|
echo -e " ${GREEN}✅ ConfigMaps deployed${NC}"
|
|
echo ""
|
|
|
|
echo " 📦 Deploying nginx application..."
|
|
kubectl apply -f nginx-nodeport-deployment.yaml
|
|
echo -e " ${GREEN}✅ nginx deployment created (worker-only)${NC}"
|
|
echo ""
|
|
|
|
echo " 📦 Creating NodePort service..."
|
|
kubectl apply -f nginx-nodeport-service.yaml
|
|
echo -e " ${GREEN}✅ NodePort service created${NC}"
|
|
echo ""
|
|
|
|
# Step 3: Wait for deployment to be ready
|
|
echo "🔍 Step 3: Waiting for deployment to be ready..."
|
|
echo ""
|
|
echo " This may take up to 60 seconds..."
|
|
|
|
if kubectl wait --for=condition=ready pod -l app=nginx-nodeport --timeout=60s 2>/dev/null; then
|
|
echo -e " ${GREEN}✅ nginx-nodeport pods are ready${NC}"
|
|
else
|
|
echo -e " ${YELLOW}⚠️ Pods taking longer than expected, continuing anyway...${NC}"
|
|
fi
|
|
echo ""
|
|
|
|
# Step 4: Check pod status
|
|
echo "🔍 Step 4: Checking pod status..."
|
|
POD_STATUS=$(kubectl get pods -l app=nginx-nodeport -o jsonpath='{.items[0].status.phase}' 2>/dev/null || echo "Unknown")
|
|
echo " Pod status: $POD_STATUS"
|
|
|
|
if [ "$POD_STATUS" != "Running" ]; then
|
|
echo -e " ${YELLOW}⚠️ Pod is not in Running state. Check with:${NC}"
|
|
echo " kubectl get pods -l app=nginx-nodeport"
|
|
echo " kubectl describe pod -l app=nginx-nodeport"
|
|
echo " kubectl logs -l app=nginx-nodeport"
|
|
fi
|
|
echo ""
|
|
|
|
# Step 5: Check service configuration
|
|
echo "🔍 Step 5: Verifying service configuration..."
|
|
SERVICE_TYPE=$(kubectl get svc nginx-nodeport-service -o jsonpath='{.spec.type}' 2>/dev/null || echo "NotFound")
|
|
NODEPORT=$(kubectl get svc nginx-nodeport-service -o jsonpath='{.spec.ports[0].nodePort}' 2>/dev/null || echo "NotFound")
|
|
IP_FAMILIES=$(kubectl get svc nginx-nodeport-service -o jsonpath='{.spec.ipFamilies}' 2>/dev/null || echo "NotFound")
|
|
|
|
echo " Service type: $SERVICE_TYPE"
|
|
echo " NodePort: $NODEPORT"
|
|
echo " IP families: $IP_FAMILIES"
|
|
|
|
if [ "$SERVICE_TYPE" != "NodePort" ]; then
|
|
echo -e " ${YELLOW}⚠️ Service type is not NodePort! Expected: NodePort, Got: $SERVICE_TYPE${NC}"
|
|
fi
|
|
|
|
if [ "$NODEPORT" != "30091" ]; then
|
|
echo -e " ${YELLOW}⚠️ NodePort is not 30091! Expected: 30091, Got: $NODEPORT${NC}"
|
|
fi
|
|
|
|
if [[ "$IP_FAMILIES" == *"IPv6"* ]]; then
|
|
echo -e " ${GREEN}✅ Dual-stack configured (includes IPv6)${NC}"
|
|
else
|
|
echo -e " ${YELLOW}⚠️ IPv6 not configured! Service will not be accessible via Mycelium IPv6${NC}"
|
|
echo " This is a critical requirement for Mycelium Cloud!"
|
|
fi
|
|
echo ""
|
|
|
|
# Step 6: Update content with current node information
|
|
echo "🔍 Step 6: Updating website content with current node information..."
|
|
echo ""
|
|
|
|
./update-content-single.sh
|
|
|
|
if [ $? -eq 0 ]; then
|
|
echo -e "${GREEN}✅ Content updated successfully${NC}"
|
|
else
|
|
echo -e "${YELLOW}⚠️ Content update failed, continuing anyway...${NC}"
|
|
fi
|
|
echo ""
|
|
|
|
# Step 7: Restart deployment to apply content changes
|
|
echo "🔍 Step 7: Restarting deployment to apply content changes..."
|
|
echo ""
|
|
|
|
kubectl rollout restart deployment/nginx-nodeport
|
|
|
|
if kubectl rollout status deployment/nginx-nodeport --timeout=60s 2>/dev/null; then
|
|
echo -e "${GREEN}✅ Deployment rolled out successfully${NC}"
|
|
else
|
|
echo -e "${YELLOW}⚠️ Rollout taking longer than expected, continuing...${NC}"
|
|
fi
|
|
echo ""
|
|
|
|
echo ""
|
|
echo "=================================="
|
|
echo "🎉 Deploy and Test Complete!"
|
|
echo "=================================="
|
|
echo ""
|
|
echo "📊 Summary:"
|
|
echo " • Resources deployed: ConfigMaps, Deployment, Service"
|
|
echo " • Service type: NodePort with dual-stack (IPv4 + IPv6)"
|
|
echo " • NodePort: 30091"
|
|
echo " • Content updated: Yes"
|
|
echo " • Tests run: Yes"
|
|
echo ""
|
|
echo "🌐 Access Information:"
|
|
POD_NAME=$(kubectl get pods -l app=nginx-nodeport -o name | head -1 2>/dev/null || echo "")
|
|
if [ -n "$POD_NAME" ]; then
|
|
POD_NODE=$(kubectl get pods -l app=nginx-nodeport -o jsonpath='{.items[0].spec.nodeName}' 2>/dev/null || echo "Unknown")
|
|
NODE_IPV6=$(kubectl get node "$POD_NODE" -o jsonpath='{range .status.addresses[?(@.type=="InternalIP")]}{.address}{"\n"}{end}' 2>/dev/null | grep -E '^[0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+$' | head -1 || echo "Unknown")
|
|
|
|
if [ "$NODE_IPV6" != "Unknown" ]; then
|
|
echo " • URL: http://[$NODE_IPV6]:30091"
|
|
echo " • Node: $POD_NODE"
|
|
echo ""
|
|
echo " To access from a machine with Mycelium installed:"
|
|
echo " curl -6 \"http://[$NODE_IPV6]:30091/\""
|
|
echo " Or open in browser:"
|
|
echo " http://[$NODE_IPV6]:30091"
|
|
else
|
|
echo " • Could not determine node IPv6 address automatically"
|
|
echo " • Check manually with:"
|
|
echo " kubectl get nodes -o wide"
|
|
fi
|
|
else
|
|
echo " • Could not find nginx-nodeport pod"
|
|
echo " • Check status with:"
|
|
echo " kubectl get pods -l app=nginx-nodeport"
|
|
fi
|
|
echo ""
|
|
echo "📋 Next Steps:"
|
|
echo " • Open the URL in a browser to see your website"
|
|
echo " • Check logs: kubectl logs -f deployment/nginx-nodeport"
|
|
echo " • Scale replicas: kubectl scale deployment nginx-nodeport --replicas=3"
|
|
echo " • Update content: ./update-content-single.sh or ./update-content-many.sh"
|
|
echo ""
|
|
echo "📚 Documentation:"
|
|
echo " • Guide: nginx-nodeport.md"
|
|
echo "" |