feat: Add nginx-load-balancer example with LoadBalancer service and automatic IPv6 assignment
This commit is contained in:
344
examples/nginx-load-balancer/update-content-load-balancer.sh
Executable file
344
examples/nginx-load-balancer/update-content-load-balancer.sh
Executable file
@@ -0,0 +1,344 @@
|
||||
#!/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'
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Mycelium Cloud - Nginx LoadBalancer Website</title>
|
||||
<meta http-equiv="refresh" content="30">
|
||||
<style>
|
||||
body {
|
||||
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
.container {
|
||||
text-align: center;
|
||||
max-width: 900px;
|
||||
padding: 2rem;
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
border-radius: 20px;
|
||||
backdrop-filter: blur(10px);
|
||||
box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37);
|
||||
}
|
||||
h1 {
|
||||
font-size: 3rem;
|
||||
margin-bottom: 1rem;
|
||||
text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
|
||||
}
|
||||
.subtitle {
|
||||
font-size: 1.2rem;
|
||||
margin-bottom: 2rem;
|
||||
opacity: 0.9;
|
||||
}
|
||||
.ipv6-info {
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
padding: 1rem;
|
||||
border-radius: 10px;
|
||||
margin: 1rem 0;
|
||||
font-family: 'Courier New', monospace;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
.status {
|
||||
display: inline-block;
|
||||
padding: 0.5rem 1rem;
|
||||
background: #4CAF50;
|
||||
border-radius: 25px;
|
||||
font-weight: bold;
|
||||
margin: 0.5rem;
|
||||
}
|
||||
.status.loadbalancer {
|
||||
background: #2196F3;
|
||||
}
|
||||
.timestamp {
|
||||
font-size: 0.8rem;
|
||||
opacity: 0.7;
|
||||
margin-top: 1rem;
|
||||
}
|
||||
.features {
|
||||
text-align: left;
|
||||
margin: 2rem 0;
|
||||
}
|
||||
.feature {
|
||||
margin: 0.5rem 0;
|
||||
padding: 0.5rem;
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
border-radius: 5px;
|
||||
}
|
||||
.security-badge {
|
||||
background: #FF9800;
|
||||
color: white;
|
||||
padding: 0.5rem 1rem;
|
||||
border-radius: 15px;
|
||||
font-weight: bold;
|
||||
margin: 1rem;
|
||||
display: inline-block;
|
||||
}
|
||||
.urls {
|
||||
background: rgba(255, 255, 255, 0.15);
|
||||
padding: 1.5rem;
|
||||
border-radius: 10px;
|
||||
margin: 1.5rem 0;
|
||||
text-align: left;
|
||||
}
|
||||
.urls h3 {
|
||||
margin-top: 0;
|
||||
color: #FFD700;
|
||||
}
|
||||
.urls ul {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
}
|
||||
.urls li {
|
||||
margin: 1rem 0;
|
||||
font-family: 'Courier New', monospace;
|
||||
font-size: 0.9rem;
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
padding: 0.8rem;
|
||||
border-radius: 6px;
|
||||
}
|
||||
.urls code {
|
||||
background: rgba(0, 0, 0, 0.3);
|
||||
padding: 0.3rem 0.6rem;
|
||||
border-radius: 4px;
|
||||
display: inline-block;
|
||||
}
|
||||
.working {
|
||||
color: #4CAF50;
|
||||
font-weight: bold;
|
||||
}
|
||||
.pending {
|
||||
color: #FFA726;
|
||||
font-weight: bold;
|
||||
}
|
||||
.node-info {
|
||||
font-size: 0.8rem;
|
||||
opacity: 0.8;
|
||||
margin-top: 0.5rem;
|
||||
}
|
||||
.load-balancing-badge {
|
||||
background: #4CAF50;
|
||||
color: white;
|
||||
padding: 0.5rem 1rem;
|
||||
border-radius: 15px;
|
||||
font-weight: bold;
|
||||
margin: 1rem;
|
||||
display: inline-block;
|
||||
}
|
||||
.info-badge {
|
||||
background: #2196F3;
|
||||
color: white;
|
||||
padding: 0.5rem 1rem;
|
||||
border-radius: 15px;
|
||||
font-weight: bold;
|
||||
margin: 0.5rem;
|
||||
display: inline-block;
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
function updateTimestamp() {
|
||||
const now = new Date();
|
||||
document.getElementById('timestamp').textContent =
|
||||
'Last updated: ' + now.toLocaleString();
|
||||
}
|
||||
|
||||
function getIPv6Address() {
|
||||
// Extract IPv6 from the current connection
|
||||
const ipv6Pattern = /\[([0-9a-f:]+)\]/;
|
||||
const match = window.location.href.match(ipv6Pattern);
|
||||
if (match) {
|
||||
document.getElementById('current-ipv6').textContent = match[1];
|
||||
} else {
|
||||
document.getElementById('current-ipv6').textContent = 'Not accessed via IPv6';
|
||||
}
|
||||
}
|
||||
|
||||
window.onload = function() {
|
||||
updateTimestamp();
|
||||
getIPv6Address();
|
||||
setInterval(updateTimestamp, 1000);
|
||||
};
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1>🌐 Mycelium Cloud</h1>
|
||||
<div class="subtitle">
|
||||
LoadBalancer Website Hosting with Automatic IPv6 Assignment!
|
||||
</div>
|
||||
|
||||
<div class="status loadbalancer">
|
||||
✅ LOADBALANCER SECURE
|
||||
</div>
|
||||
|
||||
<div class="load-balancing-badge">
|
||||
⚖️ AUTOMATIC LOAD BALANCING
|
||||
</div>
|
||||
|
||||
<div class="info-badge">
|
||||
ℹ️ 3 REPLICA DEPLOYMENT
|
||||
</div>
|
||||
|
||||
<div class="ipv6-info">
|
||||
<strong>Connected via IPv6:</strong><br>
|
||||
<span id="current-ipv6">Loading...</span>
|
||||
</div>
|
||||
|
||||
<div class="urls">
|
||||
<h3>🌐 Service Endpoint (LoadBalancer: 8080)</h3>
|
||||
<p><strong>Mycelium automatically assigns IPv6 address to LoadBalancer service:</strong></p>
|
||||
<ul>
|
||||
<li>
|
||||
<code>http://[SERVICE_IP]:8080</code>
|
||||
<span id="service-status" class="pending">⏳ PENDING</span>
|
||||
<div class="node-info">Automatic IPv6 assignment from Mycelium LoadBalancer</div>
|
||||
</li>
|
||||
</ul>
|
||||
<div id="status-message" style="background: rgba(255, 167, 38, 0.2); padding: 1rem; border-radius: 8px; margin: 1rem 0; border-left: 4px solid #FFA726;">
|
||||
<strong>ℹ️ Load Balancer Status:</strong> Mycelium is assigning IPv6 address to the service<br>
|
||||
This may take a few moments. Check status with: <code>kubectl get svc nginx-load-balancer-service</code>
|
||||
</div>
|
||||
<div style="background: rgba(76, 175, 80, 0.2); padding: 1rem; border-radius: 8px; margin: 1rem 0; border-left: 4px solid #4CAF50;">
|
||||
<strong>✅ Load Balancing:</strong> Traffic automatically distributed across 3 replicas<br>
|
||||
Service type: LoadBalancer with externalTrafficPolicy: Local
|
||||
</div>
|
||||
<p><em>Once IPv6 is assigned, anyone with Mycelium can access from anywhere!</em></p>
|
||||
</div>
|
||||
|
||||
<div class="features">
|
||||
<h3>🚀 Key Features:</h3>
|
||||
<div class="feature">⚖️ Automatic load balancing across 3 replicas</div>
|
||||
<div class="feature">🛡️ Enhanced security with network isolation</div>
|
||||
<div class="feature">🌍 Global access via Mycelium IPv6 service endpoints</div>
|
||||
<div class="feature">🔒 Standard Kubernetes LoadBalancer patterns</div>
|
||||
<div class="feature">⚡ Clean pod networking without hostNetwork</div>
|
||||
<div class="feature">🖥️ Multi-replica, multi-node Kubernetes cluster</div>
|
||||
<div class="feature">🔄 Dynamic IPv6 service endpoint assignment</div>
|
||||
</div>
|
||||
|
||||
<div class="timestamp" id="timestamp">
|
||||
Loading timestamp...
|
||||
</div>
|
||||
|
||||
<div style="margin-top: 2rem; font-size: 0.8rem;">
|
||||
Mycelium Cloud LoadBalancer Demo<br>
|
||||
Production-Ready IPv6 Website Hosting<br>
|
||||
<strong>Auto-updated every 30 seconds</strong>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// Update service status based on current information
|
||||
const serviceIp = "SERVICE_IP_PLACEHOLDER";
|
||||
const podCount = POD_COUNT_PLACEHOLDER;
|
||||
|
||||
if (serviceIp && serviceIp !== "Pending" && serviceIp !== "[pending-myelium-assignment]") {
|
||||
document.getElementById('service-status').innerHTML = '<span class="working">✅ WORKING</span>';
|
||||
document.getElementById('service-status').className = 'working';
|
||||
document.querySelector('code').innerHTML = 'http://[' + serviceIp + ']:8080';
|
||||
document.getElementById('status-message').innerHTML =
|
||||
'<strong>✅ Load Balancer Ready:</strong> IPv6 address assigned successfully<br>Service is now accessible at the IPv6 address above';
|
||||
document.getElementById('status-message').style.borderLeft = '4px solid #4CAF50';
|
||||
document.getElementById('status-message').style.background = 'rgba(76, 175, 80, 0.2)';
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
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!"
|
||||
Reference in New Issue
Block a user