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

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

问题描述

在运行Minikube时,我想连接到一台具有令人讨厌的习惯的服务器,该服务器会使用其内部IP地址从其pod内向服务注册表进行通告.

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?

推荐答案

您可以从本地主机向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主站的路由

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天全站免登陆