简体   繁体   English

将etcd集群自动配置为Docker swarm服务

[英]Automatic self-configuration of an etcd cluster as a Docker swarm service

I want to find a way to deploy an etcd cluster as a Docker Swarm service that would automatically configure itself without any interaction. 我想找到一种方法将etcd集群部署为Docker Swarm服务,该服务将自动配置而无需任何交互。 Basically, I think of something in spirit of this command: 基本上,我想到了这个命令的精神:

docker service create --name etcd --replicas 3 my-custom-image/etcd

I'm assuming that overlay network is configured to be secure and provide both encryption and authentication, so I believe I don't need TLS, not even --auto-tls . 我假设覆盖网络配置为安全并提供加密和身份验证,所以我相信我不需要TLS,甚至不需要--auto-tls Don't want an extra headache finding a way to provision the certificates, when this can be solved on the another layer. 当这可以在另一层上解决时,不希望额外的头痛找到提供证书的方法。

I need an unique --name for each instance, but I can get that from an entrypoint script that would use export ETCD_NAME=$(hostname --short) . 我需要为每个实例使用唯一的--name ,但我可以从使用export ETCD_NAME=$(hostname --short)的入口点脚本中获取。

The problem is, I'm stuck on initial configuration. 问题是,我坚持初始配置。 Based on the clustering guide there are three options, but none seems to fit: 根据聚类指南 ,有三个选项,但似乎都不适合:

  • The DNS discovery scenario is closest to what I'm looking for, but Docker doesn't support DNS SRV records discovery at the moment. DNS发现场景最接近我正在寻找的,但Docker 目前不支持DNS SRV记录发现。 I can lookup etcd and I will get all the IPs of my nodes' containers, but there are no _etcd-server._tcp records. 我可以查找etcd ,我将获得节点容器的所有IP,但是没有_etcd-server._tcp记录。
  • I cannot automatically build ETCD_INITIAL_CLUSTER because while I know the IPs, I don't know the names of the other nodes and I'm not aware about any way to figure those out. 我无法自动构建ETCD_INITIAL_CLUSTER因为虽然我知道IP,但我不知道其他节点的名称,我不知道有任何方法可以解决这些问题。 (I'm not going to expose Docker API socket to etcd container for this.) (我不打算将Docker API套接字暴露给etcd容器。)
  • There is no preexisting etcd cluster, and while supplying the initial configuration URI from discovery.etcd.io is a possible workaround I'm interested in not doing this. 没有预先存在的etcd集群,虽然从discovery.etcd.io提供初始配置URI是一种可能的解决方法,我有兴趣不这样做。 I'm aiming for "just deploy a stack from this docker-compose.yml and it'll automatically do the right thing, no questions asked" no-brainer scenario. 我的目标是“只是从这个docker-compose.yml部署一个堆栈,它会自动做正确的事情,没有问题”没有问题。

Is there any trick I can pull? 有什么技巧可以拉吗?

As you have correctly said you know the IPs of your nodes' containers, so the suggested trick is to simply build the required etcd names as derivatives of each node's IP address. 正如你已经正确地说你知道你的节点容器的IP,所以建议的技巧是简单地构建所需的etcd名称作为每个节点的IP地址的衍生物。

  • inside each container etcd is named using this particular container's IP ie etcd-$ip 在每个容器etcd中使用这个特定容器的IP命名,即etcd-$ip
  • ETCD_INITIAL_CLUSTER is populated using other containers' IPs in a similar way ETCD_INITIAL_CLUSTER以类似的方式使用其他容器的IP填充

The names could be as simple as etcd-$ip or even better ie we could use the netmask to calculate the node's IP on this network to make the names prettier. 名称可以像etcd-$ip一样简单,甚至更好,即我们可以使用netmask来计算该网络上节点的IP,使名称更漂亮。

In this case in a simple 3-nodes configuration one could end up having names like etcd-02 etcd-03 etc 在这种情况下,在一个简单的3节点配置中,最终可能会有像etcd-02 etcd-03等名称

No specific requirements exist for the name attribute, it just needs to be unique and human-readable. name属性没有特定的要求,它只需要是唯一的和人类可读的。 Although it indeed looks like a trick it might work 虽然它确实看起来像一个技巧,它可能会起作用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM