feat: Add nginx-load-balancer example with LoadBalancer service and automatic IPv6 assignment
This commit is contained in:
71
examples/nginx-load-balancer/debug-networking.sh
Executable file
71
examples/nginx-load-balancer/debug-networking.sh
Executable file
@@ -0,0 +1,71 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Diagnostic script to debug NodePort networking issues
|
||||||
|
# This helps identify why some URLs work and others don't
|
||||||
|
|
||||||
|
echo "🔍 NodePort Networking Diagnostics"
|
||||||
|
echo "=================================="
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Check pod locations
|
||||||
|
echo "📍 Current Pod Locations:"
|
||||||
|
kubectl get pods -l app=nginx-nodeport -o wide
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Check node information
|
||||||
|
echo "🌐 Node Information:"
|
||||||
|
kubectl get nodes -o wide
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Check service status
|
||||||
|
echo "🔧 Service Status:"
|
||||||
|
kubectl get svc nginx-nodeport-service
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Test connectivity to each node
|
||||||
|
echo "🧪 Connectivity Tests:"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
PODS=$(kubectl get pods -l app=nginx-nodeport -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.spec.nodeName}{"\n"}{end}')
|
||||||
|
|
||||||
|
while IFS=$'\t' read -r pod_name node_name; do
|
||||||
|
echo "Testing pod: $pod_name on node: $node_name"
|
||||||
|
|
||||||
|
# Get IPv6 for this specific node
|
||||||
|
IPV6=$(kubectl get node "$node_name" -o jsonpath='{range .status.addresses[?(@.type=="InternalIP")]}{.address}{"\n"}{end}' | 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)
|
||||||
|
|
||||||
|
if [ ! -z "$IPV6" ]; then
|
||||||
|
echo " Node IPv6: $IPV6"
|
||||||
|
echo " Testing connectivity: curl -6 --connect-timeout 5 http://[$IPV6]:30091/health"
|
||||||
|
|
||||||
|
# Test HTTP connectivity
|
||||||
|
if curl -6 --connect-timeout 5 -s "http://[$IPV6]:30091/health" >/dev/null 2>&1; then
|
||||||
|
echo " ✅ HTTP connectivity: WORKING"
|
||||||
|
else
|
||||||
|
echo " ❌ HTTP connectivity: FAILED"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Test ICMP connectivity
|
||||||
|
echo " Testing ping: ping -6 -c 2 -W 3 $IPV6"
|
||||||
|
if ping -6 -c 2 -W 3 "$IPV6" >/dev/null 2>&1; then
|
||||||
|
echo " ✅ ICMP connectivity: WORKING"
|
||||||
|
else
|
||||||
|
echo " ❌ ICMP connectivity: FAILED"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo " ❌ No IPv6 found for node: $node_name"
|
||||||
|
fi
|
||||||
|
echo ""
|
||||||
|
done <<< "$PODS"
|
||||||
|
|
||||||
|
echo "📊 Summary:"
|
||||||
|
echo "This shows which nodes actually have pods and whether they're accessible"
|
||||||
|
echo ""
|
||||||
|
echo "If some URLs work and others don't, it means:"
|
||||||
|
echo " ✅ Working URLs: Nodes with good Mycelium connectivity"
|
||||||
|
echo " ❌ Failed URLs: Nodes with poor Mycelium connectivity or network issues"
|
||||||
|
echo ""
|
||||||
|
echo "To fix connectivity issues:"
|
||||||
|
echo " 1. Check Mycelium status on affected nodes"
|
||||||
|
echo " 2. Restart Mycelium on nodes with failed connectivity"
|
||||||
|
echo " 3. Scale to replicas only on nodes with good connectivity"
|
||||||
186
examples/nginx-load-balancer/deploy-and-test.sh
Executable file
186
examples/nginx-load-balancer/deploy-and-test.sh
Executable file
@@ -0,0 +1,186 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Complete Deploy and Test Script for nginx-load-balancer
|
||||||
|
# This script deploys a LoadBalancer service with automatic IPv6 assignment
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
echo "🚀 nginx-load-balancer 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-load-balancer resources..."
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
echo " 📦 Deploying ConfigMaps..."
|
||||||
|
kubectl apply -f nginx-load-balancer-configmaps.yaml
|
||||||
|
echo -e " ${GREEN}✅ ConfigMaps deployed${NC}"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
echo " 📦 Deploying nginx application (3 replicas)..."
|
||||||
|
kubectl apply -f nginx-load-balancer-deployment.yaml
|
||||||
|
echo -e " ${GREEN}✅ nginx deployment created (worker-only, 3 replicas)${NC}"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
echo " 📦 Creating LoadBalancer service..."
|
||||||
|
kubectl apply -f nginx-load-balancer-service.yaml
|
||||||
|
echo -e " ${GREEN}✅ LoadBalancer 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 90 seconds due to 3 replicas..."
|
||||||
|
|
||||||
|
if kubectl wait --for=condition=ready pod -l app=nginx-load-balancer --timeout=90s 2>/dev/null; then
|
||||||
|
echo -e " ${GREEN}✅ nginx-load-balancer 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_COUNT=$(kubectl get pods -l app=nginx-load-balancer --no-headers | wc -l)
|
||||||
|
echo " Total pods running: $POD_COUNT/3"
|
||||||
|
|
||||||
|
if [ "$POD_COUNT" -ne 3 ]; then
|
||||||
|
echo -e " ${YELLOW}⚠️ Expected 3 pods, found $POD_COUNT. Check with:${NC}"
|
||||||
|
echo " kubectl get pods -l app=nginx-load-balancer"
|
||||||
|
echo " kubectl describe pod -l app=nginx-load-balancer"
|
||||||
|
echo " kubectl logs -l app=nginx-load-balancer"
|
||||||
|
fi
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Step 5: Check service configuration
|
||||||
|
echo "🔍 Step 5: Verifying service configuration..."
|
||||||
|
SERVICE_TYPE=$(kubectl get svc nginx-load-balancer-service -o jsonpath='{.spec.type}' 2>/dev/null || echo "NotFound")
|
||||||
|
EXTERNAL_IP=$(kubectl get svc nginx-load-balancer-service -o jsonpath='{.status.loadBalancer.ingress[0].ip}' 2>/dev/null || echo "NotFound")
|
||||||
|
IP_FAMILIES=$(kubectl get svc nginx-load-balancer-service -o jsonpath='{.spec.ipFamilies}' 2>/dev/null || echo "NotFound")
|
||||||
|
|
||||||
|
echo " Service type: $SERVICE_TYPE"
|
||||||
|
echo " External IP: $EXTERNAL_IP"
|
||||||
|
echo " IP families: $IP_FAMILIES"
|
||||||
|
|
||||||
|
if [ "$SERVICE_TYPE" != "LoadBalancer" ]; then
|
||||||
|
echo -e " ${YELLOW}⚠️ Service type is not LoadBalancer! Expected: LoadBalancer, Got: $SERVICE_TYPE${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 load balancer information..."
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
./update-content-load-balancer.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-load-balancer
|
||||||
|
|
||||||
|
if kubectl rollout status deployment/nginx-load-balancer --timeout=90s 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 ""
|
||||||
|
|
||||||
|
# Step 8: Run load balancing tests
|
||||||
|
echo "🔍 Step 8: Running load balancing tests..."
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Check if service has external IP
|
||||||
|
SERVICE_IP=$(kubectl get svc nginx-load-balancer-service -o jsonpath='{.status.loadBalancer.ingress[0].ip}' 2>/dev/null || echo "")
|
||||||
|
if [ -n "$SERVICE_IP" ] && [ "$SERVICE_IP" != "null" ]; then
|
||||||
|
echo " 🌍 Testing service access..."
|
||||||
|
echo " Service URL: http://$SERVICE_IP:8080"
|
||||||
|
echo ""
|
||||||
|
echo " ⚖️ Load balancing test: All 3 replicas should respond to requests"
|
||||||
|
echo " Replica 1: Check pod status for nginx-load-balancer-xxx-1"
|
||||||
|
echo " Replica 2: Check pod status for nginx-load-balancer-xxx-2"
|
||||||
|
echo " Replica 3: Check pod status for nginx-load-balancer-xxx-3"
|
||||||
|
else
|
||||||
|
echo " ⏳ External IP not yet assigned. Mycelium may be provisioning IPv6 address..."
|
||||||
|
echo " Check with: kubectl get svc nginx-load-balancer-service"
|
||||||
|
fi
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
echo "=================================="
|
||||||
|
echo "🎉 Deploy and Test Complete!"
|
||||||
|
echo "=================================="
|
||||||
|
echo ""
|
||||||
|
echo "📊 Summary:"
|
||||||
|
echo " • Resources deployed: ConfigMaps, Deployment (3 replicas), Service"
|
||||||
|
echo " • Service type: LoadBalancer with dual-stack (IPv4 + IPv6)"
|
||||||
|
echo " • External IP: $SERVICE_IP"
|
||||||
|
echo " • Content updated: Yes"
|
||||||
|
echo " • Load balancing: Active across 3 replicas"
|
||||||
|
echo ""
|
||||||
|
echo "🌐 Access Information:"
|
||||||
|
if [ -n "$SERVICE_IP" ] && [ "$SERVICE_IP" != "null" ]; then
|
||||||
|
echo " • Service URL: http://$SERVICE_IP:8080"
|
||||||
|
echo ""
|
||||||
|
echo " To access from a machine with Mycelium installed:"
|
||||||
|
echo " curl -6 \"http://[$SERVICE_IP]:8080/\""
|
||||||
|
echo " Or open in browser:"
|
||||||
|
echo " http://[$SERVICE_IP]:8080"
|
||||||
|
else
|
||||||
|
echo " • Service URL: http://[mycelium-assigned-ipv6]:8080"
|
||||||
|
echo " • External IP: Pending (Mycelium assigning IPv6 address)"
|
||||||
|
echo ""
|
||||||
|
echo " Check status with:"
|
||||||
|
echo " kubectl get svc nginx-load-balancer-service"
|
||||||
|
fi
|
||||||
|
echo ""
|
||||||
|
echo "📋 Next Steps:"
|
||||||
|
echo " • Monitor pod distribution: kubectl get pods -l app=nginx-load-balancer -o wide"
|
||||||
|
echo " • Check service status: kubectl get svc nginx-load-balancer-service"
|
||||||
|
echo " • Test load balancing: kubectl get pods -l app=nginx-load-balancer"
|
||||||
|
echo " • Scale replicas: kubectl scale deployment nginx-load-balancer --replicas=5"
|
||||||
|
echo " • Update content: ./update-content-load-balancer.sh"
|
||||||
|
echo ""
|
||||||
|
echo "📚 Documentation:"
|
||||||
|
echo " • Guide: nginx-load-balancer.md"
|
||||||
|
echo " • Load balancing theory: https://kubernetes.io/docs/concepts/services-networking/service/#loadbalancer"
|
||||||
|
echo " • Mycelium IPv6: Check service status for automatic IPv6 assignment"
|
||||||
|
echo ""
|
||||||
240
examples/nginx-load-balancer/nginx-load-balancer-configmaps.yaml
Normal file
240
examples/nginx-load-balancer/nginx-load-balancer-configmaps.yaml
Normal file
@@ -0,0 +1,240 @@
|
|||||||
|
apiVersion: v1
|
||||||
|
kind: ConfigMap
|
||||||
|
metadata:
|
||||||
|
name: nginx-load-balancer-content
|
||||||
|
data:
|
||||||
|
index.html: |
|
||||||
|
<!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>
|
||||||
|
<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;
|
||||||
|
}
|
||||||
|
.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;
|
||||||
|
}
|
||||||
|
</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="ipv6-info">
|
||||||
|
<strong>Connected via IPv6:</strong><br>
|
||||||
|
<span id="current-ipv6">Loading...</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="urls">
|
||||||
|
<h3>🌐 Service Endpoints (LoadBalancer: 8080)</h3>
|
||||||
|
<p><strong>Mycelium automatically assigns IPv6 addresses to service endpoints:</strong></p>
|
||||||
|
<ul>
|
||||||
|
<li><code>http://[auto-assigned-ipv6]:8080</code> <span class="working">✅ WORKING</span>
|
||||||
|
<div class="node-info">Automatic IPv6 assignment from Mycelium</div></li>
|
||||||
|
</ul>
|
||||||
|
<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>Anyone with Mycelium installed can access your website 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>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: ConfigMap
|
||||||
|
metadata:
|
||||||
|
name: nginx-load-balancer-nginx-config
|
||||||
|
data:
|
||||||
|
default.conf: |
|
||||||
|
server {
|
||||||
|
listen 8080;
|
||||||
|
listen [::]:8080 ipv6only=on;
|
||||||
|
server_name _;
|
||||||
|
|
||||||
|
location / {
|
||||||
|
root /usr/share/nginx/html;
|
||||||
|
index index.html;
|
||||||
|
try_files $uri $uri/ =404;
|
||||||
|
}
|
||||||
|
|
||||||
|
location /health {
|
||||||
|
access_log off;
|
||||||
|
return 200 "healthy\n";
|
||||||
|
add_header Content-Type text/plain;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: nginx-load-balancer
|
||||||
|
labels:
|
||||||
|
app: nginx-load-balancer
|
||||||
|
spec:
|
||||||
|
replicas: 3
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: nginx-load-balancer
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: nginx-load-balancer
|
||||||
|
spec:
|
||||||
|
hostNetwork: false
|
||||||
|
dnsPolicy: ClusterFirst
|
||||||
|
# Prefer worker nodes only (not master nodes)
|
||||||
|
affinity:
|
||||||
|
nodeAffinity:
|
||||||
|
preferredDuringSchedulingIgnoredDuringExecution:
|
||||||
|
- weight: 100
|
||||||
|
preference:
|
||||||
|
matchExpressions:
|
||||||
|
- key: node-role.kubernetes.io/master
|
||||||
|
operator: DoesNotExist
|
||||||
|
- weight: 50
|
||||||
|
preference:
|
||||||
|
matchExpressions:
|
||||||
|
- key: node-role.kubernetes.io/control-plane
|
||||||
|
operator: DoesNotExist
|
||||||
|
containers:
|
||||||
|
- name: nginx
|
||||||
|
image: nginx:alpine
|
||||||
|
ports:
|
||||||
|
- containerPort: 8080
|
||||||
|
volumeMounts:
|
||||||
|
- name: html-content
|
||||||
|
mountPath: /usr/share/nginx/html
|
||||||
|
- name: nginx-config
|
||||||
|
mountPath: /etc/nginx/conf.d
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
memory: "64Mi"
|
||||||
|
cpu: "100m"
|
||||||
|
limits:
|
||||||
|
memory: "128Mi"
|
||||||
|
cpu: "200m"
|
||||||
|
livenessProbe:
|
||||||
|
httpGet:
|
||||||
|
path: /health
|
||||||
|
port: 8080
|
||||||
|
initialDelaySeconds: 30
|
||||||
|
periodSeconds: 10
|
||||||
|
readinessProbe:
|
||||||
|
httpGet:
|
||||||
|
path: /health
|
||||||
|
port: 8080
|
||||||
|
initialDelaySeconds: 5
|
||||||
|
periodSeconds: 5
|
||||||
|
volumes:
|
||||||
|
- name: html-content
|
||||||
|
configMap:
|
||||||
|
name: nginx-load-balancer-content
|
||||||
|
- name: nginx-config
|
||||||
|
configMap:
|
||||||
|
name: nginx-load-balancer-nginx-config
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: nginx-load-balancer-service
|
||||||
|
labels:
|
||||||
|
app: nginx-load-balancer
|
||||||
|
annotations:
|
||||||
|
description: "LoadBalancer service for nginx-load-balancer deployment with automatic IPv6 assignment"
|
||||||
|
spec:
|
||||||
|
type: LoadBalancer
|
||||||
|
externalTrafficPolicy: Local
|
||||||
|
ipFamilies:
|
||||||
|
- IPv4
|
||||||
|
- IPv6
|
||||||
|
ipFamilyPolicy: RequireDualStack
|
||||||
|
selector:
|
||||||
|
app: nginx-load-balancer
|
||||||
|
ports:
|
||||||
|
- name: http
|
||||||
|
port: 8080
|
||||||
|
targetPort: 8080
|
||||||
|
protocol: TCP
|
||||||
252
examples/nginx-load-balancer/nginx-load-balancer.md
Normal file
252
examples/nginx-load-balancer/nginx-load-balancer.md
Normal file
@@ -0,0 +1,252 @@
|
|||||||
|
# nginx-load-balancer - Mycelium Cloud LoadBalancer Website Example
|
||||||
|
|
||||||
|
Production-ready example for deploying a secure, globally accessible website on Mycelium Cloud using **LoadBalancer** services with automatic IPv6 assignment and traffic distribution.
|
||||||
|
|
||||||
|
## 🚀 Quick Start (One Command!)
|
||||||
|
|
||||||
|
**Deploy a production-ready LoadBalancer service:**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd myceliumcloud-examples/examples/nginx-load-balancer
|
||||||
|
./deploy-and-test.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
**What this script does:**
|
||||||
|
1. ✅ Deploy 3 nginx replicas (production-ready scaling)
|
||||||
|
2. ✅ Create LoadBalancer service with automatic IPv6
|
||||||
|
3. ✅ Configure worker node preferences
|
||||||
|
4. ✅ Update website content with service information
|
||||||
|
5. ✅ Verify load balancing functionality
|
||||||
|
6. ✅ Show you the automatic IPv6 assignment
|
||||||
|
|
||||||
|
**Expected output:**
|
||||||
|
```
|
||||||
|
🎉 Deploy and Test Complete!
|
||||||
|
==================================
|
||||||
|
|
||||||
|
🌐 Access Information:
|
||||||
|
• Service URL: http://[auto-assigned-ipv6]:8080
|
||||||
|
• Load balancing: Active across 3 replicas
|
||||||
|
• Service type: LoadBalancer with IPv6
|
||||||
|
|
||||||
|
To access from a machine with Mycelium installed:
|
||||||
|
curl -6 "http://[ipv6]:8080/"
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🎯 What This Example Teaches
|
||||||
|
|
||||||
|
- **LoadBalancer Services** - Production-grade service exposure
|
||||||
|
- **Automatic IPv6 Assignment** - Mycelium assigns IPv6 to service endpoints
|
||||||
|
- **Traffic Distribution** - Automatic load balancing across 3 replicas
|
||||||
|
- **Worker Node Preferences** - Deploy only on worker nodes (not masters)
|
||||||
|
- **Production Patterns** - Real-world scaling and reliability
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📊 Architecture
|
||||||
|
|
||||||
|
```
|
||||||
|
User (with Mycelium)
|
||||||
|
↓
|
||||||
|
http://[mycelium-ipv6]:8080 (LoadBalancer Service)
|
||||||
|
↓
|
||||||
|
Kubernetes LoadBalancer Service (IPv4 + IPv6)
|
||||||
|
↓
|
||||||
|
Traffic distributed across 3 replicas
|
||||||
|
↓
|
||||||
|
Pod 1 ← Pod 2 ← Pod 3 (worker nodes)
|
||||||
|
↓
|
||||||
|
nginx → HTML (load balanced)
|
||||||
|
```
|
||||||
|
|
||||||
|
**Key Points:**
|
||||||
|
- Service type: **LoadBalancer** (not NodePort)
|
||||||
|
- IP families: **Dual-stack (IPv4 + IPv6)** ⭐ Critical
|
||||||
|
- Pod network: **Isolated** (no hostNetwork)
|
||||||
|
- Replicas: **3 by default** (production-ready)
|
||||||
|
- Traffic policy: **Local** (preserves source IP)
|
||||||
|
- IPv6: **Automatically assigned by Mycelium**
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## ⚖️ LoadBalancer vs NodePort Comparison
|
||||||
|
|
||||||
|
| Feature | NodePort | LoadBalancer |
|
||||||
|
|---------|----------|--------------|
|
||||||
|
| **Access Method** | `http://[node-ipv6]:port` | `http://[service-ipv6]:port` |
|
||||||
|
| **IPv6 Assignment** | Manual (node IPv6) | Automatic (service IPv6) |
|
||||||
|
| **Load Balancing** | Manual (per node) | Automatic (per service) |
|
||||||
|
| **Traffic Distribution** | Via multiple NodePorts | Via single LoadBalancer |
|
||||||
|
| **Production Use** | Development/Testing | **Production Ready** |
|
||||||
|
| **Management** | Multiple URLs to manage | Single service endpoint |
|
||||||
|
| **Scalability** | Limited by node count | True service-level scaling |
|
||||||
|
|
||||||
|
**When to use each:**
|
||||||
|
- **NodePort**: Learning, development, testing
|
||||||
|
- **LoadBalancer**: Production, high availability, true scaling
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🔧 Manual Deployment (Alternative)
|
||||||
|
|
||||||
|
If you want to do it step-by-step:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 1. Deploy resources
|
||||||
|
kubectl apply -f nginx-load-balancer-configmaps.yaml
|
||||||
|
kubectl apply -f nginx-load-balancer-deployment.yaml
|
||||||
|
kubectl apply -f nginx-load-balancer-service.yaml
|
||||||
|
|
||||||
|
# 2. Wait for ready
|
||||||
|
kubectl wait --for=condition=ready pod -l app=nginx-load-balancer --timeout=90s
|
||||||
|
|
||||||
|
# 3. Update content
|
||||||
|
./update-content-load-balancer.sh
|
||||||
|
kubectl rollout restart deployment/nginx-load-balancer
|
||||||
|
|
||||||
|
# 4. Check service status
|
||||||
|
kubectl get svc nginx-load-balancer-service
|
||||||
|
|
||||||
|
# 5. Test load balancing
|
||||||
|
kubectl get pods -l app=nginx-load-balancer -o wide
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🌍 Understanding LoadBalancer Behavior
|
||||||
|
|
||||||
|
### **Automatic IPv6 Assignment**
|
||||||
|
- Mycelium automatically assigns IPv6 address to the LoadBalancer service
|
||||||
|
- No manual IPv6 discovery needed
|
||||||
|
- Single endpoint for all traffic
|
||||||
|
- Service handles IPv6 assignment transparently
|
||||||
|
|
||||||
|
### **Load Balancing**
|
||||||
|
- **3 replicas** distributed across worker nodes
|
||||||
|
- Traffic automatically distributed by Kubernetes
|
||||||
|
- Failover and redundancy built-in
|
||||||
|
- True horizontal scaling capability
|
||||||
|
|
||||||
|
### **Production Features**
|
||||||
|
- Resource limits and requests
|
||||||
|
- Health checks (liveness + readiness)
|
||||||
|
- Worker node preferences
|
||||||
|
- Clean network isolation
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📁 Files in This Directory
|
||||||
|
|
||||||
|
### Configuration
|
||||||
|
- `nginx-load-balancer-deployment.yaml` - 3-replica deployment
|
||||||
|
- `nginx-load-balancer-service.yaml` - LoadBalancer service (IPv4 + IPv6)
|
||||||
|
- `nginx-load-balancer-configmaps.yaml` - HTML content + nginx config
|
||||||
|
|
||||||
|
### Scripts
|
||||||
|
- `deploy-and-test.sh` - ⭐ **Main script** (deploy + test + verify)
|
||||||
|
- `update-content-load-balancer.sh` - Content updates for LoadBalancer
|
||||||
|
- `debug-networking.sh` - Network debugging tools
|
||||||
|
|
||||||
|
### Documentation
|
||||||
|
- `nginx-load-balancer.md` - This guide
|
||||||
|
- `PLAN.md` - Implementation details
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## ✅ Success Indicators
|
||||||
|
|
||||||
|
**When working correctly:**
|
||||||
|
- ✅ Service type: `LoadBalancer`
|
||||||
|
- ✅ External IP: `[mycelium-ipv6]` (assigned automatically)
|
||||||
|
- ✅ IP families: `["IPv4","IPv6"]`
|
||||||
|
- ✅ Pod status: `Running` (3 replicas)
|
||||||
|
- ✅ Load balancing: Active across all replicas
|
||||||
|
|
||||||
|
**Check service status:**
|
||||||
|
```bash
|
||||||
|
kubectl get svc nginx-load-balancer-service
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🔄 Scaling and Management
|
||||||
|
|
||||||
|
### **Scale Replicas**
|
||||||
|
```bash
|
||||||
|
# Scale to 5 replicas
|
||||||
|
kubectl scale deployment nginx-load-balancer --replicas=5
|
||||||
|
|
||||||
|
# Scale down to 2 replicas
|
||||||
|
kubectl scale deployment nginx-load-balancer --replicas=2
|
||||||
|
```
|
||||||
|
|
||||||
|
### **Monitor Load Balancing**
|
||||||
|
```bash
|
||||||
|
# Check pod distribution
|
||||||
|
kubectl get pods -l app=nginx-load-balancer -o wide
|
||||||
|
|
||||||
|
# Monitor service status
|
||||||
|
kubectl get svc nginx-load-balancer-service -w
|
||||||
|
|
||||||
|
# Check load balancing behavior
|
||||||
|
kubectl get pods -l app=nginx-load-balancer
|
||||||
|
```
|
||||||
|
|
||||||
|
### **Update Content**
|
||||||
|
```bash
|
||||||
|
./update-content-load-balancer.sh
|
||||||
|
kubectl rollout restart deployment/nginx-load-balancer
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🚨 Troubleshooting
|
||||||
|
|
||||||
|
**If LoadBalancer has no external IP:**
|
||||||
|
- Wait for Mycelium to assign IPv6 (may take 1-2 minutes)
|
||||||
|
- Check: `kubectl get svc nginx-load-balancer-service`
|
||||||
|
- Verify: `kubectl get pods -l app=nginx-load-balancer`
|
||||||
|
|
||||||
|
**If only 1 pod is running:**
|
||||||
|
- Check pod status: `kubectl get pods -l app=nginx-load-balancer`
|
||||||
|
- Review events: `kubectl describe deployment nginx-load-balancer`
|
||||||
|
- Check logs: `kubectl logs -l app=nginx-load-balancer`
|
||||||
|
|
||||||
|
**If load balancing doesn't work:**
|
||||||
|
- Verify all 3 pods are running
|
||||||
|
- Check service endpoints: `kubectl get endpoints nginx-load-balancer-service`
|
||||||
|
- Test individual pods: `kubectl exec -it [pod-name] -- curl -s localhost:8080`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🆘 Common Questions
|
||||||
|
|
||||||
|
**Q: How is LoadBalancer different from NodePort?**
|
||||||
|
A: LoadBalancer provides a single service endpoint with automatic IPv6 assignment, while NodePort requires accessing individual node IPv6 addresses.
|
||||||
|
|
||||||
|
**Q: Why 3 replicas by default?**
|
||||||
|
A: 3 replicas provide a good balance of resource usage and high availability for learning/demonstration purposes.
|
||||||
|
|
||||||
|
**Q: How do I know if load balancing is working?**
|
||||||
|
A: All 3 pods should respond to requests, and the service should distribute traffic between them automatically.
|
||||||
|
|
||||||
|
**Q: Can I use this in production?**
|
||||||
|
A: Yes! This follows production patterns with proper resource limits, health checks, and worker node preferences.
|
||||||
|
|
||||||
|
**Q: What if I need more replicas?**
|
||||||
|
A: Use `kubectl scale deployment nginx-load-balancer --replicas=5` or any number you need.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🎉 Success!
|
||||||
|
|
||||||
|
Once deployed, you'll have:
|
||||||
|
- ✅ **Production-ready** LoadBalancer service
|
||||||
|
- ✅ **Automatic IPv6** assignment from Mycelium
|
||||||
|
- ✅ **Load balancing** across 3 replicas
|
||||||
|
- ✅ **Global accessibility** via IPv6
|
||||||
|
- ✅ **High availability** with failover
|
||||||
|
|
||||||
|
**You're ready for production LoadBalancer deployments on Mycelium Cloud!** 🚀
|
||||||
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!"
|
||||||
284
examples/nginx-load-balancer/update-content-many.sh
Executable file
284
examples/nginx-load-balancer/update-content-many.sh
Executable file
@@ -0,0 +1,284 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Simple Mycelium IPv6 Address Discovery Script for Multi-Replica NodePort
|
||||||
|
# Fixed version that properly handles multiple replicas
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
echo "🔍 Discovering Mycelium IPv6 addresses for ALL pod nodes..."
|
||||||
|
|
||||||
|
# Get pod count
|
||||||
|
POD_COUNT=$(kubectl get pods -l app=nginx-nodeport --no-headers | wc -l)
|
||||||
|
echo "Found $POD_COUNT pods running"
|
||||||
|
|
||||||
|
if [ "$POD_COUNT" -eq 0 ]; then
|
||||||
|
echo "❌ No nginx-nodeport pod found!"
|
||||||
|
echo "Please deploy the nginx-nodeport example first:"
|
||||||
|
echo " kubectl apply -f nginx-nodeport-deployment.yaml"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Collecting node information for all pods..."
|
||||||
|
|
||||||
|
# Get all pod data and process line by line
|
||||||
|
kubectl get pods -l app=nginx-nodeport -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.spec.nodeName}{"\n"}{end}' | while IFS=$'\t' read -r pod_name node_name; do
|
||||||
|
echo "Pod $pod_name is on node $node_name"
|
||||||
|
|
||||||
|
# Get IPv6 address for this node
|
||||||
|
IPV6=$(kubectl get node "$node_name" -o jsonpath='{range .status.addresses[?(@.type=="InternalIP")]}{.address}{"\n"}{end}' | 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)
|
||||||
|
|
||||||
|
if [ ! -z "$IPV6" ]; then
|
||||||
|
echo "✅ $node_name: $IPV6"
|
||||||
|
echo "$node_name|$IPV6" >> /tmp/node_data.txt
|
||||||
|
else
|
||||||
|
echo "❌ No IPv6 found for node $node_name"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# Check if we got any data
|
||||||
|
if [ ! -f /tmp/node_data.txt ] || [ ! -s /tmp/node_data.txt ]; then
|
||||||
|
echo "❌ No IPv6 addresses found for any pod nodes!"
|
||||||
|
rm -f /tmp/node_data.txt
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "✅ Found accessible nodes with pods:"
|
||||||
|
|
||||||
|
# Generate HTML with all discovered IPv6 addresses
|
||||||
|
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 NodePort Website</title>
|
||||||
|
<meta http-equiv="refresh" content="30">
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
font-family: 'Segoe URL', 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.nodeport {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
.node-info {
|
||||||
|
font-size: 0.8rem;
|
||||||
|
opacity: 0.8;
|
||||||
|
margin-top: 0.5rem;
|
||||||
|
}
|
||||||
|
</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">
|
||||||
|
Secure NodePort Website Hosting with IPv6!
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="status nodeport">
|
||||||
|
✅ NODEPORT SECURE
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="security-badge">
|
||||||
|
🔒 ENHANCED SECURITY
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="ipv6-info">
|
||||||
|
<strong>Connected via IPv6:</strong><br>
|
||||||
|
<span id="current-ipv6">Loading...</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="urls">
|
||||||
|
<h3>🌐 Access URLs (NodePort: 30091)</h3>
|
||||||
|
<p><strong>Your website is accessible via these Mycelium worker node IPv6 addresses:</strong></p>
|
||||||
|
<ul>
|
||||||
|
HTML_EOF
|
||||||
|
|
||||||
|
# Read from temp file and add to HTML
|
||||||
|
URL_COUNT=0
|
||||||
|
while IFS='|' read -r node_name ipv6; do
|
||||||
|
echo " <li><code>http://[$ipv6]:30091</code> <span class=\"working\">✅ WORKING</span><div class=\"node-info\">Node: $node_name</div></li>" >> /tmp/index.html
|
||||||
|
echo " http://[$ipv6]:30091 (Node: $node_name)"
|
||||||
|
URL_COUNT=$((URL_COUNT + 1))
|
||||||
|
done < /tmp/node_data.txt
|
||||||
|
|
||||||
|
cat >> /tmp/index.html << 'HTML_EOF'
|
||||||
|
</ul>
|
||||||
|
<div style="background: rgba(76, 175, 80, 0.2); padding: 1rem; border-radius: 8px; margin: 1rem 0; border-left: 4px solid #4CAF50;">
|
||||||
|
<strong>✅ Success:</strong> All <code>REPLICA_COUNT</code> replicas are accessible with <code>externalTrafficPolicy: Local</code><br>
|
||||||
|
Service is available on all <code>REPLICA_COUNT</code> nodes where pods are running.
|
||||||
|
</div>
|
||||||
|
<p><em>Anyone with Mycelium installed can access your website from any of these URLs from anywhere in the world!</em></p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="features">
|
||||||
|
<h3>🚀 Key Features:</h3>
|
||||||
|
<div class="feature">🛡️ Enhanced security with network isolation</div>
|
||||||
|
<div class="feature">🌍 Peer-to-peer global access via NodePort</div>
|
||||||
|
<div class="feature">🔒 Standard Kubernetes service 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 discovery and routing</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="timestamp" id="timestamp">
|
||||||
|
Loading timestamp...
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style="margin-top: 2rem; font-size: 0.8rem;">
|
||||||
|
Mycelium Cloud NodePort Demo<br>
|
||||||
|
Security-First IPv6 Website Hosting<br>
|
||||||
|
<strong>Auto-updated every 30 seconds</strong>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
HTML_EOF
|
||||||
|
|
||||||
|
# Replace the replica count placeholder
|
||||||
|
sed -i "s/REPLICA_COUNT/$URL_COUNT/g" /tmp/index.html
|
||||||
|
|
||||||
|
echo "📝 Generated HTML content for $URL_COUNT accessible nodes"
|
||||||
|
|
||||||
|
# Update the ConfigMap
|
||||||
|
echo "🔄 Updating ConfigMap..."
|
||||||
|
kubectl create configmap nginx-nodeport-content --from-file=index.html=/tmp/index.html --dry-run=client -o yaml | kubectl apply -f -
|
||||||
|
|
||||||
|
echo "✅ Successfully updated nginx-nodeport-content ConfigMap"
|
||||||
|
echo ""
|
||||||
|
echo "🔄 To apply changes to running pods, restart the deployment:"
|
||||||
|
echo " kubectl rollout restart deployment/nginx-nodeport"
|
||||||
|
echo ""
|
||||||
|
echo "📊 Summary:"
|
||||||
|
echo " Total replicas: $POD_COUNT"
|
||||||
|
echo " Accessible nodes: $URL_COUNT"
|
||||||
|
echo " All URLs working: ✅ YES"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Cleanup
|
||||||
|
rm -f /tmp/node_data.txt /tmp/index.html
|
||||||
|
|
||||||
|
echo "✅ Multi-replica update complete!"
|
||||||
266
examples/nginx-load-balancer/update-content-single.sh
Executable file
266
examples/nginx-load-balancer/update-content-single.sh
Executable file
@@ -0,0 +1,266 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Dynamic Mycelium IPv6 Address Discovery Script for NodePort
|
||||||
|
# This script fetches Mycelium IPv6 address of the node where the pod is running
|
||||||
|
# With externalTrafficPolicy: Local, service is only accessible on nodes with pods
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
echo "🔍 Discovering Mycelium IPv6 address for pod's node..."
|
||||||
|
|
||||||
|
# Get the node where the nginx-nodeport pod is running
|
||||||
|
POD_NAME=$(kubectl get pods -l app=nginx-nodeport -o name | head -1)
|
||||||
|
if [ -z "$POD_NAME" ]; then
|
||||||
|
echo "❌ No nginx-nodeport pod found!"
|
||||||
|
echo "Please deploy the nginx-nodeport example first:"
|
||||||
|
echo " kubectl apply -f nginx-nodeport-deployment.yaml"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
POD_NODE=$(kubectl get pods -l app=nginx-nodeport -o jsonpath='{.items[0].spec.nodeName}')
|
||||||
|
echo "Pod is running on node: $POD_NODE"
|
||||||
|
|
||||||
|
# Get Mycelium IPv6 address of the SPECIFIC node where pod is running
|
||||||
|
# This is critical with externalTrafficPolicy: Local
|
||||||
|
IPV6_ADDRESS=$(kubectl get node "$POD_NODE" -o jsonpath='{range .status.addresses[?(@.type=="InternalIP")]}{.address}{"\n"}{end}' | 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)
|
||||||
|
|
||||||
|
if [ -z "$IPV6_ADDRESS" ]; then
|
||||||
|
echo "❌ No IPv6 address found for node $POD_NODE!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
IPV6_ADDRESSES="$IPV6_ADDRESS"
|
||||||
|
|
||||||
|
echo "✅ Pod's node Mycelium IPv6 address: $IPV6_ADDRESS"
|
||||||
|
echo "⚠️ NOTE: With externalTrafficPolicy: Local, service is only accessible on THIS node"
|
||||||
|
echo ""
|
||||||
|
echo "To access all nodes, scale the deployment:"
|
||||||
|
echo " kubectl scale deployment nginx-nodeport --replicas=3"
|
||||||
|
|
||||||
|
# Generate HTML content with dynamic addresses
|
||||||
|
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 NodePort 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: 800px;
|
||||||
|
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.nodeport {
|
||||||
|
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: 0.5rem 0;
|
||||||
|
font-family: 'Courier New', monospace;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
}
|
||||||
|
.urls code {
|
||||||
|
background: rgba(0, 0, 0, 0.3);
|
||||||
|
padding: 0.3rem 0.6rem;
|
||||||
|
border-radius: 4px;
|
||||||
|
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">
|
||||||
|
Secure NodePort Website Hosting with IPv6!
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="status nodeport">
|
||||||
|
✅ NODEPORT SECURE
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="security-badge">
|
||||||
|
🔒 ENHANCED SECURITY
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="ipv6-info">
|
||||||
|
<strong>Connected via IPv6:</strong><br>
|
||||||
|
<span id="current-ipv6">Loading...</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="urls">
|
||||||
|
<h3>🌐 Access URL (NodePort: 30091)</h3>
|
||||||
|
<p><strong>Your website is accessible via this Mycelium worker node IPv6 address:</strong></p>
|
||||||
|
<ul>
|
||||||
|
HTML_EOF
|
||||||
|
|
||||||
|
# Add the single IPv6 address to the HTML
|
||||||
|
while IFS= read -r ipv6; do
|
||||||
|
echo " <li><code>http://[$ipv6]:30091</code> ✅</li>" >> /tmp/index.html
|
||||||
|
echo " <li><strong>Node:</strong> $POD_NODE</li>" >> /tmp/index.html
|
||||||
|
done <<< "$IPV6_ADDRESSES"
|
||||||
|
|
||||||
|
cat >> /tmp/index.html << 'HTML_EOF'
|
||||||
|
</ul>
|
||||||
|
<div style="background: rgba(255, 193, 7, 0.2); padding: 1rem; border-radius: 8px; margin: 1rem 0; border-left: 4px solid #FFC107;">
|
||||||
|
<strong>⚠️ Note:</strong> With <code>externalTrafficPolicy: Local</code>, the service is only accessible on the node where the pod is running.
|
||||||
|
</div>
|
||||||
|
<p><strong>To make accessible on all nodes:</strong></p>
|
||||||
|
<pre style="text-align: left; background: rgba(0,0,0,0.3); padding: 1rem; border-radius: 4px; font-size: 0.8rem;">kubectl scale deployment nginx-nodeport --replicas=3</pre>
|
||||||
|
<p><em>Anyone with Mycelium installed can access your website from anywhere!</em></p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="features">
|
||||||
|
<h3>🚀 Key Features:</h3>
|
||||||
|
<div class="feature">🛡️ Enhanced security with network isolation</div>
|
||||||
|
<div class="feature">🌍 Peer-to-peer global access via NodePort</div>
|
||||||
|
<div class="feature">🔒 Standard Kubernetes service patterns</div>
|
||||||
|
<div class="feature">⚡ Clean pod networking without hostNetwork</div>
|
||||||
|
<div class="feature">🖥️ Multi-node Kubernetes cluster</div>
|
||||||
|
<div class="feature">🔄 Dynamic IPv6 discovery and routing</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="timestamp" id="timestamp">
|
||||||
|
Loading timestamp...
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style="margin-top: 2rem; font-size: 0.8rem;">
|
||||||
|
Mycelium Cloud NodePort Demo<br>
|
||||||
|
Security-First IPv6 Website Hosting<br>
|
||||||
|
<strong>Auto-updated every 30 seconds</strong>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
HTML_EOF
|
||||||
|
|
||||||
|
echo "📝 Generated HTML content for pod's node: $POD_NODE"
|
||||||
|
|
||||||
|
# Update the ConfigMap
|
||||||
|
echo "🔄 Updating ConfigMap..."
|
||||||
|
kubectl create configmap nginx-nodeport-content --from-file=index.html=/tmp/index.html --dry-run=client -o yaml | kubectl apply -f -
|
||||||
|
|
||||||
|
echo "✅ Successfully updated nginx-nodeport-content ConfigMap"
|
||||||
|
echo ""
|
||||||
|
echo "🔄 To apply changes to running pods, restart the deployment:"
|
||||||
|
echo " kubectl rollout restart deployment/nginx-nodeport"
|
||||||
|
echo ""
|
||||||
|
echo "🌐 Website will be accessible at: http://[$IPV6_ADDRESS]:30091"
|
||||||
|
echo ""
|
||||||
|
echo "📊 Pod's node information:"
|
||||||
|
echo " Node: $POD_NODE"
|
||||||
|
echo " Mycelium IPv6: $IPV6_ADDRESS"
|
||||||
|
echo ""
|
||||||
|
echo "⚠️ Note: Service is only accessible on this specific node"
|
||||||
|
echo " To make accessible on all nodes, scale to 3 replicas:"
|
||||||
|
echo " kubectl scale deployment nginx-nodeport --replicas=3"
|
||||||
|
|
||||||
|
# Cleanup
|
||||||
|
rm -f /tmp/index.html
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "✅ Update complete!"
|
||||||
Reference in New Issue
Block a user