From 14172e21648d3449608547b5f0cf4fc109dc9935 Mon Sep 17 00:00:00 2001 From: mik-tf Date: Fri, 7 Nov 2025 09:28:16 -0500 Subject: [PATCH] feat: Add multi-replica IPv6 discovery scripts for nginx-nodeport example --- .../nginx-nodeport/update-content-fixed.sh | 284 ++++++++++++++++ .../nginx-nodeport/update-content-multi.sh | 312 ++++++++++++++++++ 2 files changed, 596 insertions(+) create mode 100755 examples/nginx-nodeport/update-content-fixed.sh create mode 100755 examples/nginx-nodeport/update-content-multi.sh diff --git a/examples/nginx-nodeport/update-content-fixed.sh b/examples/nginx-nodeport/update-content-fixed.sh new file mode 100755 index 0000000..25cf6a2 --- /dev/null +++ b/examples/nginx-nodeport/update-content-fixed.sh @@ -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' + + + + + + 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:

+
    +HTML_EOF + +# Read from temp file and add to HTML +URL_COUNT=0 +while IFS='|' read -r node_name ipv6; do + echo "
  • http://[$ipv6]:30091 ✅ WORKING
    Node: $node_name
  • " >> /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' +
+
+ ✅ 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!" \ No newline at end of file diff --git a/examples/nginx-nodeport/update-content-multi.sh b/examples/nginx-nodeport/update-content-multi.sh new file mode 100755 index 0000000..1188b62 --- /dev/null +++ b/examples/nginx-nodeport/update-content-multi.sh @@ -0,0 +1,312 @@ +#!/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' + + + + + + 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:

+
    +HTML_EOF + +# Add all accessible IPv6 addresses to the HTML +for i in "${!IPV6_ADDRESSES[@]}"; do + ipv6="${IPV6_ADDRESSES[$i]}" + node="${NODES_WITH_PODS[$i]}" + echo "
  • http://[$ipv6]:30091 ✅ WORKING
    Node: $node
  • " >> /tmp/index.html +done + +cat >> /tmp/index.html << 'HTML_EOF' +
+
+ ✅ 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/${#IPV6_ADDRESSES[@]}/g" /tmp/index.html + +echo "📝 Generated HTML content for ${#IPV6_ADDRESSES[@]} 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 "🌐 Website will be accessible at ALL of these URLs:" +for i in "${!IPV6_ADDRESSES[@]}"; do + echo " http://[${IPV6_ADDRESSES[$i]}]:30091 (Node: ${NODES_WITH_PODS[$i]})" +done +echo "" +echo "📊 Summary:" +echo " Total replicas: $POD_COUNT" +echo " Accessible nodes: ${#IPV6_ADDRESSES[@]}" +echo " All URLs working: ✅ YES" +echo "" + +# Cleanup +rm -f /tmp/index.html + +echo "✅ Multi-replica update complete!" \ No newline at end of file