如何从Kubernetes Pod连接到私有IP [英] How to connect to a private IP from Kubernetes Pod
问题描述
我正在尝试从Pod内连接到私有IP.从Pod ping通到该IP会返回不可访问的状态.但是,我可以从主机系统ping该IP.将流量从Pod路由到目标专用IP的最佳方法是什么?
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?
推荐答案
Pod不允许直接在kubernetes网络外部连接.您可以在此处中找到更多详细信息.要连接外部IP,您必须定义Endpoints
,并且kubernets会将请求从Pod内部重定向到该IP.如果您的私有IP需要任何额外的任务(例如DNS配置),或者其他任何事情都将超出kubernetes的范围.对于kubernetes,您将需要定义Endpoints
.创建您Endpoints
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 kubernets 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
现在,您可以使用Endpoints
名称从Pod内部进行连接.但是最好通过Service
访问Endpoints
.您可以在此处找到更多详细信息. .
您可以在此处找到类似的答案和流程图.
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.
这篇关于如何从Kubernetes Pod连接到私有IP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!