How to access pod IP from outside

7/21/2020

I'm rookie to k8s.

I know the pod IP is set in range by --cluster-cidr. eg. 10.244.0.0/18

My question is how to access the pod IP from outside the k8s cluster.

I heard of 2 ways to do that:

    1. Make Docker bridge use a self defined Linux bridge, some tricks in /etc/docker/daemon.json, then add route records at the router device by ip route add 10.244.0.0/18 via {k8sNodeIp}(or something like that, I dont know details).
    1. Similar to the upper one, but they seems accomplish that without the "bridge tricks", just add some route records(tell me if I'm wrong).

These solutions are from two different teams.

I dont know if the k8s network plugin got involved, the first one uses flannel and the last one uses calico.

Any docs about that?

-- Li Hao Su
calico
flannel
kubernetes

1 Answer

7/21/2020

Answer

You can use kubectl port-forward to talk directly to containers in Pods for the purposes of debugging / development.

E.g. kubectl port-forward mypod 5000:6000

See docs here

More Info

This command will set up a proxy on your workstation so that you can run, for example:

curl localhost:5000/api/v1/status

This request will be forwarded to the API Server, which will then forward your request to the Pod you specify in the port-forward command.

-- Serge
Source: StackOverflow