diff --git a/examples/nginx-nodeport/update-content.sh b/examples/nginx-nodeport/update-content.sh index d6be150..d5efdc2 100755 --- a/examples/nginx-nodeport/update-content.sh +++ b/examples/nginx-nodeport/update-content.sh @@ -1,28 +1,41 @@ #!/bin/bash # Dynamic Mycelium IPv6 Address Discovery Script for NodePort -# This script fetches Mycelium IPv6 addresses from worker nodes and generates HTML content +# 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 addresses from worker nodes..." +echo "🔍 Discovering Mycelium IPv6 address for pod's node..." -# Fetch IPv6 addresses from cluster worker nodes -IPV6_ADDRESSES=$(kubectl get nodes -l kubernetes.io/role!=master -o jsonpath='{range .items[*]}{range .status.addresses[?(@.type=="InternalIP")]}{.address}{"\n"}{end}{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]+$') - -if [ -z "$IPV6_ADDRESSES" ]; then - echo "⚠️ No IPv6 addresses found from worker nodes!" - echo "Trying all nodes..." - IPV6_ADDRESSES=$(kubectl get nodes -o jsonpath='{range .items[*]}{range .status.addresses[?(@.type=="InternalIP")]}{.address}{"\n"}{end}{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]+$') -fi - -if [ -z "$IPV6_ADDRESSES" ]; then - echo "❌ No IPv6 addresses found!" +# 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 -echo "✅ Found IPv6 addresses:" -echo "$IPV6_ADDRESSES" +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' @@ -180,18 +193,24 @@ cat > /tmp/index.html << 'HTML_EOF'
Your website is accessible via these Mycelium worker node IPv6 addresses:
+Your website is accessible via this Mycelium worker node IPv6 address:
http://[$ipv6]:30091 ✅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!