将内部 Kubernetes IP 地址路由到主机系统 [英] Routing an internal Kubernetes IP address to the host system

查看:29
本文介绍了将内部 Kubernetes IP 地址路由到主机系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在运行 Minikube 时,我想连接到一个服务器,该服务器有一个恼人的习惯,即从其 pod 内部将其内部 IP 地址通告给服务注册中心.

While running Minikube, I want to connect to a server that has the annoying habit of announcing itself to a service registry with its internal IP address from inside its pod.

但是由于遗留原因,我必须首先连接到此注册表并从中检索该服务器的 IP 地址.在我看来,从我的开发机器访问这个服务器的唯一方法是桥接到内部网络,这样我就可以访问 Minikube 的网络.有没有简单的方法可以做到这一点?

However for legacy reasons I have to connect to this registry first and retrieve that server's ip address from it. The only way to access this server from my dev machine, it seems to me, is bridging to the internal network, so I can access the networking of the Minikube. Is there an easy way to do this?

推荐答案

可以添加从localhost到k8内网的路由

You can add a route to the k8 internal network from localhost

使用minikube ip地址添加到内网的路由

Add a route to the internal network using the minikube ip address

$ sudo ip route add 172.17.0.0/16 via $(minikube ip)  # linux
$ sudo route -n add 172.17.0.0/16 $(minikube ip) # OSX

可以使用 kubectl get service 命令找到您的子网掩码

your subnet mask could be found using kubectl get service command

通过部署一个测试容器并从本地主机连接到它来测试路由

Test the route by deploying a test container and connect to it from localhost

$ kubectl run monolith --image=kelseyhightower/monolith:1.0.0 --port=80
$ IP=$(kubectl get pod  -l run=monolith -o jsonpath='{.items[0].status.podIP }')
$ curl http://$IP
{"message":"Hello"}

也可以添加路由到K8 master

You can also add a route to K8 master

sudo route -n add 10.0.0.0/24 $(minikube ip)

这仅对本地开发有用,您应该使用 NodePortLoadBalancer 在生产中公开 pod.

This is only useful for local development, you should use NodePort or LoadBalancer for exposing pods in production.

这篇关于将内部 Kubernetes IP 地址路由到主机系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆