Port forwarding in Kubernetes allows you to access internal pod services (like a web server, database, or API) on your local machine, even if they’re not exposed externally via a Service or Ingress.
When you use K9s (a terminal-based UI for managing Kubernetes clusters), it gives you a quick and user-friendly way to set up port forwarding to pods—without manually typing out kubectl port-forward commands.
K9s itself doesn’t directly configure port forwarding, but it offers a convenient way to initiate port forwarding to Kubernetes pods using a terminal UI. Here’s how to do port forwarding using K9s:
Steps to Use Port Forwarding in K9s
- Start K9s
Run this in your terminal: bashCopyEditk9s - Navigate to Pods (
:podsor justpo)- Use arrow keys or
/to filter and select the pod you want.
- Use arrow keys or
- Select the Target Pod
- Move the cursor to highlight the desired pod.
- Press
Shift+F(uppercase F) to start port forwarding.
- Enter Local and Remote Ports
- You’ll be prompted to specify ports in the format:
[localPort]:[remotePort]For example:8080:80This maps your localhost:8080 to the pod’s port 80.
- You’ll be prompted to specify ports in the format:
- Verify Forwarding
- K9s will show a status line that the port is forwarded.
- You can now access the service at
localhost:[localPort].
- Stop Forwarding
- Use
Ctrl+Cor select the pod again and pressShift+Fto toggle off forwarding.
- Use
