-1

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?

David Maze
  • 130,717
  • 29
  • 175
  • 215
Li Hao Su
  • 23
  • 4
  • 2
    why not use Kubernetes Service of type NodePort? – Arghya Sadhu Jul 21 '20 at 06:49
  • The recommended way of accessing a pod is via services. Using IP is not easy to mange and scale. If you don't need to consider scalability maybe you don't need k8s. – Ken Chen Jul 21 '20 at 06:52
  • @ArghyaSadhu These solutions are not for production usage, just for some debug or develop conveniences.I cant find any docs about that. – Li Hao Su Jul 21 '20 at 07:20

1 Answers1

0

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
  • 634
  • 4
  • 9
  • Sorry this is not what I want.I setup a **OpenVPN** server on one of the k8s edge nodes, then with a vpn client on my windows desktop to connect to the k8s network.It works for me. – Li Hao Su Jul 22 '20 at 00:31
  • Right yep, I answered just this `My question is how to access the pod IP from outside the k8s cluster.` – Serge Jul 22 '20 at 01:29