Sharang Chopra
Sharang Chopra

Reputation: 256

How to forward a k8 pod's port via jumphost

I can ssh into a jumphost from where I can accesss k8 cluster. there is a particular pod which has a UI exposed on port 4040, how can I view that on my local browser ?

What I have figured out so far, by executing the below command

kubectl port-forward podName 4040:4040

I can now access the UI (by text based browser) on jumphost

Upvotes: 1

Views: 2601

Answers (2)

Mohan
Mohan

Reputation: 597

Even though there is an accepted answer, my situation is little different. After connecting to the jumphost with ssh, I have tried the above port forwarding command and it was working fine but for some reason I can't access these exposed port using step 2 from my local machine.

Here is what I did. Added --address 0.0.0.0 to the existing port forward command.

  1. Inside the Jumphost

kubectl port-forward podname --address 0.0.0.0 7000:8080 -n namespace

  1. From my local machine, created a tunnel because I can't access our jumphost with user@jumphostname. So I have to use the resource id to specify the jumphost id, so I followed this command.

az network bastion tunnel --name hubname --resource-group resourcegroupname --subscription subscriptionid --target-resource-id vmresourceid --resource-port 7000 --port 8000

From local machine you can start using via postman or browser with http://localhost:8000

It might be useful to someone. :)

Upvotes: 2

Sharang Chopra
Sharang Chopra

Reputation: 256

Had to be done in two steps

1st run kubectl port-forward podName 4040:4040 from jumpbox

2nd run ssh -L 4040:localhost:4040 -i some_key.pem user@jumpbox-server from the local machine

access http://localhost:4040 using browser

Upvotes: 5

Related Questions