DEV Community

loading...
Cover image for How to forward a port in K8s

How to forward a port in K8s

Maxime Guilbert
Just a dev who touches a lot of things and wants to share his experiences. (or just want to note somewhere things to don't forget)
・1 min read

This is a simple thing that I've discover recently, it's not a revolution or something really hidden, but I think it's cool to share it!

So to forward a service port in Kubernetes, you just have to do

kubectl port-forward element to expose [local port:]pod/service/deploy... port

examples

# Expose port 80 of the service on the local port 80
kubectl port-forward svc/example-service 80

# Expose port 80 of the pod on the local port 36000
kubectl port-forward pod/pod-test 36000:80

# Expose port 27017 of the deployment on a random free local port
kubectl port-forward deployment/mongo :27017
Enter fullscreen mode Exit fullscreen mode

Links


I hope it will help you!

Discussion (0)