Difference between kubectl port-forwarding and NodePort service

4/4/2020

Whats the difference between kubectl port-forwarding (which forwards port from local host to the pod in the cluster to gain access to cluster resources) and NodePort Service type ?

-- Rad4
kubernetes

2 Answers

4/4/2020

If you use port forwarding kubectl port forward svc/{your_service} -n {service_namespace} you just need a clusterIP, kubectl will handle the traffic for you. Kubectl will be the proxy for your traffic

If you use nodeport for access your service means you need to open port on the worker nodes.

-- Fauzan
Source: StackOverflow

4/6/2020

You are comparing two completely different things. You should compare ClusterIP, NodePort, LoadBalancer and Ingress.

The first and most important difference is that NodePort expose is persistent while by doing it using port-forwarding, you always have to run kubectl port-forward ... and kept it active.

kubectl port-forward is meant for testing, labs, troubleshooting and not for long term solutions. It will create a tunnel between your machine and kubernetes so this solution will serve demands from/to your machine.

NodePort can give you long term solution and it can serves demands from/to anywhere inside network your nodes reside.

-- mWatney
Source: StackOverflow