我的Docker映像是否需要其自己的领事客户端实例? [英] Does my docker images need its own consul client instances?

查看:82
本文介绍了我的Docker映像是否需要其自己的领事客户端实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将dockerized应用程序拆分为几个容器(一些前端和后端服务器,负载均衡器,mysql,elasticsearch等)。负载平衡器的配置需要知道哪个容器已启动,因此我正在使用Consul服务发现注册服务。

I've got a dockerized application split in several containers (a few frontend and backend servers, load balancer, mysql, elasticsearch, etc.). The configuration of the load balancer needs to know which containers are up and so I'm registering services with Consul service discovery.

但是我不确定这是否是一个容器。在每个Docker容器上运行Consul代理的好主意,而不是使用Docker主机来监督所有正在运行的Docker容器并通过Consul的HTTP-API注册它们。

But I'm not quite sure if it's a good idea to run a consul agent on every docker container instead of using the docker host to supervise all the running docker containers and register them via Consul's HTTP-API.

我可以遵循的任何最佳实践吗?

Is there any best practice around I can follow?

推荐答案

您不需要在每个Docker容器上运行领事代理,您可以只需通过将领事馆的DNS暴露给本地就可以利用领事。以下不是从容器中获取信息,但无论如何您都会对我的想法有所了解。

You don't need to run a consul agent on every docker container, you can simply take advantage of consul by exposing it's DNS to your local. Following is not from a container but you will get the idea anyways as to what I am doing.

以下是我用来运行代理的命令

following is the command I am using to run my agent

consul agent -data-dir /var/lib/consul/ -config-dir /etc/consul.d/ -bind 10.X.X.X -dns-port 53 -join consul-master

注意:我为/ etc / hosts添加了一个条目使用IP的consul-master,我还在/etc/resolv.conf文件中为127.0.0.1添加了名称服务器。

Note: I have added a /etc/hosts entry for consul-master with it's IP and I have also added a nameserver for 127.0.0.1 in the /etc/resolv.conf file.

目录/etc/consul.d /保存该服务的配置文件。下面是一个示例:

The directory /etc/consul.d/ holds my configuration file for the service. Following is an example:

{
  "service": {
    "name": "stackoverflow",
    "tags": [
      "example"
    ],
    "port": 5000
  }
}

现在,一旦我的领事代理运行,我就可以通过dig命令检查任何具有领事代理(服务器/客户端)的主机上的服务。 http api请求如下:

Now once my consul agent is running, I can check on any host with consul agent (server/client) for the service via dig command or the http api request as follows:

curl http://stackoverflow.service.consul:80/api/v1/ping
{"success":true,"message":"pong"}

对于DNS:

dig @127.0.0.1 -p 53 stackoverflow.service.consul

; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.62.rc1.55.amzn1 <<>> @127.0.0.1 -p 53 tracker.service.consul
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 57167
;; flags: qr aa rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
;; WARNING: recursion requested but not available

;; QUESTION SECTION:
;tracker.service.consul.        IN  A

;; ANSWER SECTION:
tracker.service.consul. 0   IN  A   X.X.X.X

;; Query time: 1 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Fri Jul  7 11:29:01 2017
;; MSG SIZE  rcvd: 56

希望能提供帮助并给出清晰的构想

Hope that helps and gives a clear idea of it

这篇关于我的Docker映像是否需要其自己的领事客户端实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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