Problem
User wants to expose deployments outside of the cluster
kubectl expose deployment MYDEPLOYMENT --name=nodeport --port=80 --target-port=8080 --type=NodePort
Check your Nodes IP Addresses
NODEPORT=$(kubectl get -o jsonpath="{.spec.ports[0].nodePort}" services nodeport)
NODES=$(kubectl get nodes -o jsonpath='{ $.items[*].status.addresses[?(@.type=="InternalIP")].address }')
for node in $NODES; do curl -s $node:$NODEPORT | grep -i client_address; done
To avoid Kubernetes preserve the client source IP, kube-proxy only proxies proxy requests to local endpoints, and does not forward traffic to other nodes
kubectl patch svc nodeport -p '{"spec":{"externalTrafficPolicy":"Local"}}'
Attachment: command.txt
We do this for a living.
Kubernetes, DevOps and platform engineering, delivered in days — not another weekend lost to a stack trace.
Start a project →