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

🌐 Mycelium Cloud

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

🌐 Access URL (NodePort: 30091)

Your website is accessible via this Mycelium worker node IPv6 address:

⚠️ Note: With externalTrafficPolicy: Local, the service is only accessible on the node where the pod is running.

To make accessible on all nodes:

kubectl scale deployment nginx-nodeport --replicas=3

Anyone with Mycelium installed can access your website from anywhere!

🚀 Key Features:

🛡️ Enhanced security with network isolation
🌍 Peer-to-peer global access via NodePort
🔒 Standard Kubernetes service patterns
⚡ Clean pod networking without hostNetwork
🖥️ 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 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!"