#!/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
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!"