Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to connect to a private IP from Kubernetes Pod

I am trying to connect to a private IP from within a pod. Ping to that IP from the pod returns unreachable. However, I am able to ping that IP from the host system. What is the best way to route the traffic from the pod to the destination private IP?

like image 942
Forkmohit Avatar asked Sep 17 '25 01:09

Forkmohit


1 Answers

Pods are not allowed to connect directly outside of kubernetes network. You can find more details here. To connect external IP you have to define Endpoints and Kubernetes will redirect request from inside pod to that IP. If you private IP need any extra task like DNS configure or anything else will is out of kubernetes. For kubernetes you will need to define Endpoints. Create you Endpoints

kind: Endpoints
apiVersion: v1
metadata:
  name: local-ip
subsets:
 - addresses:
     - ip: 10.240.0.4  # IP of your desire end point
   ports:
     - port: 27017     # Port that you want to access

Now you can connect from inside you pods using Endpoints name. But better to access Endpoints through Service. You can find more details here. You can find similar answer and flow diagram here.

like image 178
Shalauddin Ahamad Shuza Avatar answered Sep 19 '25 15:09

Shalauddin Ahamad Shuza