How to bind local ports to Kubernetes pods for port forwarding using Kubernetes Python client?

679 views Asked by At

I need to port forward to my pods from my local machine. It can be done easily with kubectl:

kubectl port-forward my_pod -n namespace --address 0.0.0.0 5000:5000

But I have to achieve this using Python client. I can get the socket to the remote port with:

pf = portforward(api.connect_post_namespaced_pod_portforward, pod_name, namespace, ports='5000')
pf.socket(5000)

Is that possible to bind a local port to this socket so that I can visit the webpage on the remote port from my local browser?

0

There are 0 answers