Forum Navigation
You need to log in to create posts and topics.

Expose service outside of the k8s cluster

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”}}’

 

Uploaded files: