#!/bin/bash # Dynamic Mycelium IPv6 Address Discovery Script for Multi-Replica NodePort # This script fetches Mycelium IPv6 addresses from ALL nodes where pods are running # Works correctly with externalTrafficPolicy: Local and multiple replicas set -e echo "🔍 Discovering Mycelium IPv6 addresses for ALL pod nodes..." # Get ALL nginx-nodeport pods 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 # Collect all node information declare -A NODE_IPV6_MAP declare -a NODES_WITH_PODS declare -a IPV6_ADDRESSES echo "Collecting node information for all pods..." # Read pod data into array first to avoid subshell issues mapfile -t POD_DATA < <(kubectl get pods -l app=nginx-nodeport -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.spec.nodeName}{"\n"}{end}') for line in "${POD_DATA[@]}"; do IFS=$'\t' read -r pod_name node_name <<< "$line" if [ ! -z "$node_name" ] && [ "${NODE_IPV6_MAP[$node_name]+isset}" = "" ]; then 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 NODE_IPV6_MAP[$node_name]=$IPV6 NODES_WITH_PODS+=("$node_name") IPV6_ADDRESSES+=("$IPV6") echo " ✅ Node $node_name has IPv6: $IPV6" else echo " ❌ No IPv6 found for node $node_name" fi fi done # Build the IPv6 addresses string IPV6_LIST="" FIRST=true for ipv6 in "${IPV6_ADDRESSES[@]}"; do if [ "$FIRST" = true ]; then IPV6_LIST="$ipv6" FIRST=false else IPV6_LIST="$IPV6_LIST $ipv6" fi done if [ ${#IPV6_ADDRESSES[@]} -eq 0 ]; then echo "❌ No IPv6 addresses found for any pod nodes!" exit 1 fi echo "✅ Found ${#IPV6_ADDRESSES[@]} accessible nodes with pods:" for i in "${!NODES_WITH_PODS[@]}"; do echo " ${NODES_WITH_PODS[$i]}: ${IPV6_ADDRESSES[$i]}" done # Generate HTML content with all accessible 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!