How to map nodePort to my own defined port

10/1/2019

I have a service which is accessible on 8081. If I do via docker-compose or swarm without any specific changing on port it's work.

 http://$(minikube ip):8081

but when i run my app via Kubernetes(minikube) is assign a nodePort in range of 30000-32767. Then i have to call as follow:

http://$(minikube ip):30546

which is not acceptable from my service. Is there any way to map randomly given port to my own defined port? When call second url then i am getting connection refused I also used

kubectl port forward my-service 8081

but still no success.

--
kubernetes

1 Answer

10/1/2019

kubectl port-forward command is incorrect. try below one

kubectl port-forward svc/my-service 8081:8081

then you should be able to access the service at http//:127.0.0.1:8081

-- P Ekambaram
Source: StackOverflow