DEV Community

Cover image for How to forward a port in K8s
Maxime Guilbert
Maxime Guilbert

Posted on • Edited on

2 1

How to forward a port in K8s

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!

Image of Datadog

The Essential Toolkit for Front-end Developers

Take a user-centric approach to front-end monitoring that evolves alongside increasingly complex frameworks and single-page applications.

Get The Kit

Top comments (0)