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!

AWS GenAI LIVE image

How is generative AI increasing efficiency?

Join AWS GenAI LIVE! to find out how gen AI is reshaping productivity, streamlining processes, and driving innovation.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay