如何最好地利用Kubernetes/minikube DNS进行本地开发 [英] How to best utilize Kubernetes/minikube DNS for local development

查看:128
本文介绍了如何最好地利用Kubernetes/minikube DNS进行本地开发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在转向使用Kubernetes.通过内置的dns访问k8s部署中的其他已部署服务很简单.因此,如果我有一个名为app1的pod/服务,一个名为app2的pod/服务,而app1需要调用app2,它可以只使用"app2",而k8s dns可以发挥其魔力,并且一切正常.很好,因为我们不需要在所有环境中都拥有app1_host和app2_host的配置管理开销.

We are switching to using Kubernetes. It is simple to access other deployed services within a k8s deployment via the built in dns. So if I have pod/service named app1 and a pod/service named app2 and app1 needs to call app2, it can just use "app2" and k8s dns works its magic and everything works. It is nice because we don't need the config mgmt overhead of having a app1_host and app2_host for all environments.

这也可以使用minikube在本地工作.如果将app1和app2部署到minikube中,它们可以通过服务名称(与应用名称匹配)相互引用

This also works locally using minikube. If app1 and app2 are deployed into minikube, they can reference each other via the service name (which matches the app names)

但是,我遇到问题的地方是地方发展.假设我要在本地IDE中处理app1.我可以在minikube中启动app2,但是现在,如果我希望app1在minikube中访问app2 ...我不能再仅使用"app2".我必须ping minikube/kubectl api并获取正在运行的IP和端口,然后才能在本地使用它...这使我们回到使用主机/端口类型的配置mgmt.

However, where I am running into issues is local development. Let's say I want to work on app1 in my local IDE. I can spin up app2 in minikube, but now if I want app1 to access app2 in minikube...i can no longer use just "app2". I have to ping minikube/kubectl api and get the running IP and Port and then I can use that locally... which makes we go back to using HOST/PORT type config mgmt.

我们可以更新/etc/hosts文件并将app2指向minikube IP,但是我仍然需要找出外部/公开端口是什么.

We could update /etc/hosts file and point app2 to the minikube IP, but I would still need to find out what the external/exposed port is.

我们可以使用config mgmt主机/端口,并在启动时从minikube/k8s api中动态填充它们.这是推荐的方式吗?有什么已经做到了(类似于envconsul)?

We could use config mgmt host/port and on start up dynamically populate them from minikube/k8s api. Is that the recommended way? Is there something that already does that (akin to envconsul)?

在尝试在IDE中本地工作但在minikube或k8s中运行依赖服务时,是否有更好的/更优雅的解决方案可以利用k8s dns的功能?

Is there a better/more elegant solution that I can harness the power of k8s dns when trying to work locally in an IDE but have dependent services running in minikube or k8s?

谢谢

推荐答案

CI/CD工具

每次更改代码时,始终重新构建并重新部署您的应用程序:

CI/CD Tools

Always re-build and re-deploy your app on every code change:

将仅切换出已修改的文件,并允许您使用热重载,例如使用nodemon for nodejs:

Will only switch out files that have been modified and allow you to use hot reloading, e.g. with nodemon for nodejs:

这篇关于如何最好地利用Kubernetes/minikube DNS进行本地开发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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