Docker 和 Consul 的例子:需要澄清

Docker and Consul by example: need clarification

我正在学习 Docker-Swarm with Consul,发现了一些我不太理解的问题。基本上,我使用 Consul Sevice Discovery 创建了一个 Docker-Swarm 集群(node-01 和 node-02)。然后我 运行 一个多容器应用程序(具有 Mongo 的 Express 应用程序),我可以看到它在 node-02 上 运行ning。为了 运行 它,我必须进去找到我的 node-02 的 IP 地址,然后打开浏览器。

它工作正常,只是我希望我可以访问某个虚拟 IP(或 DNS),然后 Consul 服务(或 Swarm)会将其转换为节点的正确 IP 地址- 02 在这个例子中。

下一项是当我登录 Consul web UI 时,我希望看到 'nodes' 菜单下的节点,但事实并非如此。我还希望获得 'applications' 或 'services' 的概述,我在 node-01 和 node-02 上 运行ning,但事实并非如此。

我的问题是:

  1. 有人可以解释为什么我需要手动找出我的应用程序在集群中的哪个节点上 运行ning。无法想象这是在更大的部署中完成的。
  2. 有人可以解决为什么我在 Consul UI 中看不到 'nodes' 和 'services' 吗?

注意:尽管我已经在博客 post(带有屏幕截图)中记录了完整的设置,但我尽量做到尽可能简短,以供那些想要查看更多详细信息的人使用。 Go to blog post

问题 1

I would like to access the service without having to use the Swarm agent's IP address

解决方案

是可行的,你只需要启动一个reverse proxy such as nginx in a container (here are the official nginx images)。在此容器启动时,使用带有应用程序名称的选项 --link。这样这个容器的IP地址就会添加到反向代理容器的文件/etc/hosts中(记得使用--name--hostname)。 运行 特定节点上的此反向代理容器。 所以摆脱IP地址问题的解决方案是在特定节点(然后是特定IP地址)上部署另一个容器?是的!但是使用 --link 将使这个问题可扩展 ;)

问题 2

I was expecting to see the nodes under the 'nodes' menu, but that seems not to be the case.

你是什么意思?你期待什么?需要查询k,v-storage DB吗?

检查这个:https://github.com/vmudigal/microservices-sample

                     Microservices Sample Architecture