#!/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' Mycelium Cloud - Nginx NodePort Website

🌐 Mycelium Cloud

Secure NodePort Website Hosting with IPv6!
✅ NODEPORT SECURE
🔒 ENHANCED SECURITY
Connected via IPv6:
Loading...

🌐 Access URLs (NodePort: 30091)

Your website is accessible via these Mycelium worker node IPv6 addresses:

✅ Success: All REPLICA_COUNT replicas are accessible with externalTrafficPolicy: Local
Service is available on all REPLICA_COUNT nodes where pods are running.

Anyone with Mycelium installed can access your website from any of these URLs from anywhere in the world!

🚀 Key Features:

🛡️ Enhanced security with network isolation
🌍 Peer-to-peer global access via NodePort
🔒 Standard Kubernetes service patterns
⚡ Clean pod networking without hostNetwork
🖥️ Multi-replica, multi-node Kubernetes cluster
🔄 Dynamic IPv6 discovery and routing
Loading timestamp...
Mycelium Cloud NodePort Demo
Security-First IPv6 Website Hosting
Auto-updated every 30 seconds
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!"