#!/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'
Your website is accessible via these Mycelium worker node IPv6 addresses:
http://[$ipv6]:30091 ✅ WORKINGREPLICA_COUNT replicas are accessible with externalTrafficPolicy: LocalREPLICA_COUNT nodes where pods are running.
Anyone with Mycelium installed can access your website from any of these URLs from anywhere in the world!