#!/bin/bash # LoadBalancer Content Update Script for nginx-load-balancer # This script updates content showing the LoadBalancer service's IPv6 address set -e echo "🔍 Discovering LoadBalancer service information..." # Check if service exists if ! kubectl get svc nginx-load-balancer-service &> /dev/null; then echo "❌ nginx-load-balancer-service not found!" echo "Please deploy the nginx-load-balancer example first:" echo " kubectl apply -f nginx-load-balancer-deployment.yaml" exit 1 fi # Get service information SERVICE_IP=$(kubectl get svc nginx-load-balancer-service -o jsonpath='{.status.loadBalancer.ingress[0].ip}' 2>/dev/null || echo "Pending") SERVICE_TYPE=$(kubectl get svc nginx-load-balancer-service -o jsonpath='{.spec.type}' 2>/dev/null || echo "Unknown") echo "Service type: $SERVICE_TYPE" echo "External IP: $SERVICE_IP" if [ "$SERVICE_TYPE" != "LoadBalancer" ]; then echo "❌ Service is not a LoadBalancer type!" exit 1 fi if [ -z "$SERVICE_IP" ] || [ "$SERVICE_IP" = "Pending" ] || [ "$SERVICE_IP" = "null" ]; then echo "âŗ External IP not yet assigned. Mycelium may be assigning IPv6 address..." echo "This is normal - LoadBalancer services get their IPv6 from Mycelium automatically" echo "Check service status with: kubectl get svc nginx-load-balancer-service" # We'll still create content but note that IP is pending SERVICE_IP="[pending-myelium-assignment]" else echo "✅ LoadBalancer service has IPv6: $SERVICE_IP" fi # Get pod count for display POD_COUNT=$(kubectl get pods -l app=nginx-load-balancer --no-headers | wc -l) echo "Running pods: $POD_COUNT/3" # Generate HTML content for LoadBalancer cat > /tmp/index.html << 'HTML_EOF' Mycelium Cloud - Nginx LoadBalancer Website

🌐 Mycelium Cloud

LoadBalancer Website Hosting with Automatic IPv6 Assignment!
✅ LOADBALANCER SECURE
âš–ī¸ AUTOMATIC LOAD BALANCING
â„šī¸ 3 REPLICA DEPLOYMENT
Connected via IPv6:
Loading...

🌐 Service Endpoint (LoadBalancer: 8080)

Mycelium automatically assigns IPv6 address to LoadBalancer service:

â„šī¸ Load Balancer Status: Mycelium is assigning IPv6 address to the service
This may take a few moments. Check status with: kubectl get svc nginx-load-balancer-service
✅ Load Balancing: Traffic automatically distributed across 3 replicas
Service type: LoadBalancer with externalTrafficPolicy: Local

Once IPv6 is assigned, anyone with Mycelium can access from anywhere!

🚀 Key Features:

âš–ī¸ Automatic load balancing across 3 replicas
đŸ›Ąī¸ Enhanced security with network isolation
🌍 Global access via Mycelium IPv6 service endpoints
🔒 Standard Kubernetes LoadBalancer patterns
⚡ Clean pod networking without hostNetwork
đŸ–Ĩī¸ Multi-replica, multi-node Kubernetes cluster
🔄 Dynamic IPv6 service endpoint assignment
Loading timestamp...
Mycelium Cloud LoadBalancer Demo
Production-Ready IPv6 Website Hosting
Auto-updated every 30 seconds
HTML_EOF # Replace placeholders sed -i "s/SERVICE_IP_PLACEHOLDER/$SERVICE_IP/g" /tmp/index.html sed -i "s/POD_COUNT_PLACEHOLDER/$POD_COUNT/g" /tmp/index.html echo "📝 Generated HTML content for LoadBalancer service" # Update the ConfigMap echo "🔄 Updating ConfigMap..." kubectl create configmap nginx-load-balancer-content --from-file=index.html=/tmp/index.html --dry-run=client -o yaml | kubectl apply -f - echo "✅ Successfully updated nginx-load-balancer-content ConfigMap" echo "" echo "🔄 To apply changes to running pods, restart the deployment:" echo " kubectl rollout restart deployment/nginx-load-balancer" echo "" if [ -n "$SERVICE_IP" ] && [ "$SERVICE_IP" != "Pending" ] && [ "$SERVICE_IP" != "null" ]; then echo "🌐 LoadBalancer service accessible at: http://[$SERVICE_IP]:8080" echo "" echo "📊 Service information:" echo " Service type: $SERVICE_TYPE" echo " External IP: $SERVICE_IP" echo " Pods running: $POD_COUNT/3" echo " Load balancing: Active across all replicas" else echo "âŗ LoadBalancer IPv6 assignment in progress..." echo " Service type: $SERVICE_TYPE" echo " Pods running: $POD_COUNT/3" echo " Status: Mycelium assigning IPv6 address" echo "" echo " Check progress with:" echo " kubectl get svc nginx-load-balancer-service" fi echo "" echo "🔧 Management commands:" echo " Check pods: kubectl get pods -l app=nginx-load-balancer" echo " Scale replicas: kubectl scale deployment nginx-load-balancer --replicas=5" echo " Service status: kubectl get svc nginx-load-balancer-service" echo "" # Cleanup rm -f /tmp/index.html echo "✅ LoadBalancer content update complete!"