11#cloud-config
22---
33coreos:
4- etcd:
5- # generate a new token for each unique cluster from https://discovery.etcd.io/new
6- # uncomment the following line and replace it with your discovery URL
7- # discovery: https://discovery.etcd.io/12345693838asdfasfadf13939923
8- addr: $private_ipv4:4001
9- peer-addr: $private_ipv4:7001
10- # give etcd more time if it's under heavy load - prevent leader election thrashing
11- peer-election-timeout: 2000
12- # heartbeat interval should ideally be 1/4 or 1/5 of peer election timeout
13- peer-heartbeat-interval: 500
144 fleet:
155 # We have to set the public_ip here so this works on Vagrant -- otherwise, Vagrant VMs
166 # will all publish the same private IP. This is harmless for cloud providers.
@@ -20,6 +10,46 @@ coreos:
2010 units:
2111 - name: etcd.service
2212 command: start
13+ content: |
14+ [Unit]
15+ Description=etcd2 container
16+ Requires=early-docker.service
17+ After=early-docker.service
18+ Before=early-docker.target
19+
20+ [Service]
21+ User=etcd
22+ PermissionsStartOnly=true
23+ Restart=always
24+ RestartSec=10s
25+ LimitNOFILE=40000
26+ EnvironmentFile=/etc/environment
27+ Environment="ETCD_IMAGE=quay.io/coreos/etcd:v2.0.13"
28+ Environment="ETCD_ELECTION_TIMEOUT=2000"
29+ Environment="ETCD_HEARTBEAT_INTERVAL=400"
30+ Environment="ETCD_DATA_DIR=/var/lib/etcd2"
31+ Environment="ETCD_NAME=%m"
32+ Environment="DOCKER_HOST=unix:///var/run/early-docker.sock"
33+ ExecStartPre=/bin/sh -c "docker history $ETCD_IMAGE >/dev/null 2>&1 || docker pull $ETCD_IMAGE"
34+ ExecStartPre=/bin/sh -c "docker inspect $ETCD_NAME >/dev/null 2>&1 && docker rm -f $ETCD_NAME || true"
35+ ExecStart=/usr/bin/docker run --net=host --rm \
36+ --volume=${ETCD_DATA_DIR}:/var/lib/etcd2 \
37+ --volume=/usr/share/ca-certificates:/etc/ssl/certs:ro \
38+ -p 4001:4001 -p 2380:2380 -p 2379:2379 -p 7001:7001 \
39+ --name ${ETCD_NAME} \
40+ ${ETCD_IMAGE} \
41+ -name ${ETCD_NAME} \
42+ -data-dir /var/lib/etcd2 \
43+ -advertise-client-urls http://${COREOS_PRIVATE_IPV4}:2379,http://${COREOS_PRIVATE_IPV4}:4001 \
44+ -listen-client-urls http://0.0.0.0:2379,http://0.0.0.0:4001 \
45+ -initial-advertise-peer-urls http://${COREOS_PRIVATE_IPV4}:2380,http://${COREOS_PRIVATE_IPV4}:7001 \
46+ -listen-peer-urls http://0.0.0.0:2380,http://0.0.0.0:7001 \
47+ --heartbeat-interval ${ETCD_HEARTBEAT_INTERVAL} \
48+ --election-timeout ${ETCD_ELECTION_TIMEOUT} \
49+ --discovery #DISCOVERY_URL
50+ ExecStop=-/usr/bin/docker stop $ETCD_NAME
51+ - name: etcd2.service
52+ mask: true
2353 - name: docker-tcp.socket
2454 command: start
2555 enable: true
@@ -244,9 +274,16 @@ write_files:
244274 /usr/bin/docker exec deis-store-admin ceph mon remove `hostname -f` # fixme
245275 /usr/bin/docker stop deis-store-metadata || true
246276 fi
247- NODE=$(curl -L http://127.0.0.1:7001/v2/admin/machines/`cat /etc/machine-id`)
248- # remove from etcd cluster
249- if [ $NODE != 'null' ]; then
250- /usr/bin/curl -L -XDELETE http://127.0.0.1:7001/v2/admin/machines/`cat /etc/machine-id`
277+
278+ # TODO: remove the next check once etcdctl is using etcd2
279+ ETCDCTL=/usr/bin/etcdctl
280+ if ! $ETCDCTL --version | grep -q "etcdctl version 2.0."; then
281+ ETCD_VERSION=2.0.13
282+ curl -sSL https://github.com/coreos/etcd/releases/download/v${ETCD_VERSION}/etcd-v${ETCD_VERSION}-linux-amd64.tar.gz | \
283+ tar zxv -C /opt/bin etcd-v${ETCD_VERSION}-linux-amd64/etcdctl --strip=1
284+ ETCDCTL="/opt/bin/etcdctl"
251285 fi
286+ # removing the node from etcd
287+ NODE=$($ETCDCTL member list | grep `cat /etc/machine-id` | cut -d ':' -f 1)
288+ $ETCDCTL member remove $NODE
252289manage_etc_hosts: localhost
0 commit comments