Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between kubectl port-forwarding and NodePort service

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 ?

like image 575
Rad4 Avatar asked Jan 25 '23 04:01

Rad4


1 Answers

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 serve demands from/to anywhere inside the network your nodes reside.

like image 146
Mark Watney Avatar answered Apr 08 '23 03:04

Mark Watney