I want to find a way to deploy an etcd cluster as a Docker Swarm service that would automatically configure itself without any interaction. 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
. 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)
.
The problem is, I'm stuck on initial configuration. Based on the clustering guide there are three options, but none seems to fit:
etcd
and I will get all the IPs of my nodes' containers, but there are no _etcd-server._tcp
records.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. (I'm not going to expose Docker API socket to etcd container for this.)docker-compose.yml
and it'll automatically do the right thing, no questions asked" no-brainer scenario.Is there any trick I can pull?
If either container was starting properly you should have a running etcd cluster which is available for use by stacks in your Docker Swarm or any other container there is. And it's private in that no external client is capable of accessing this cluster.
As mentioned in the previous paragraph, Swarm remains to be utilized by both Docker and Kubernetes as a core engine for container storage. Granted that Kubernetes is in a dominant position on the market right now, its adoption and usage of Swarm continue to be in the spotlight.
etcd is an open source distributed key-value store used to hold and manage the critical information that distributed systems need to keep running. Most notably, it manages the configuration data, state data, and metadata for Kubernetes, the popular container orchestration platform.
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.
etcd
is named using this particular container's IP i.e. etcd-$ip
ETCD_INITIAL_CLUSTER
is populated using other containers' IPs in a similar wayThe names could be as simple as etcd-$ip
or even better i.e. we could use the netmask
to calculate the node’s IP on this network to make the names prettier.
In this case in a simple 3-nodes configuration one could end up having names like etcd-02
etcd-03
etc
No specific requirements exist for the name attribute, it just needs to be unique and human-readable. Although it indeed looks like a trick it might work
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With