Skip to content

Commit c94e9a8

Browse files
aledbfmboersma
authored andcommitted
chore(*): use etcd2 inside a container
1 parent ff73695 commit c94e9a8

12 files changed

Lines changed: 69 additions & 32 deletions

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ dev-cluster: discovery-url
3030
deisctl install platform
3131

3232
discovery-url:
33-
sed -e "s,# discovery:,discovery:," -e "s,discovery: https://discovery.etcd.io/.*,discovery: $$(curl -s -w '\n' https://discovery.etcd.io/new)," contrib/coreos/user-data.example > contrib/coreos/user-data
33+
sed -e "s,discovery #DISCOVERY_URL,discovery $$(curl -s -w '\n' https://discovery.etcd.io/new?size=$$DEIS_NUM_INSTANCES)," contrib/coreos/user-data.example > contrib/coreos/user-data
3434

3535
build: check-docker
3636
@$(foreach C, $(COMPONENTS), $(MAKE) -C $(C) build &&) echo done

Vagrantfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ Vagrant.configure("2") do |config|
9090
end
9191

9292
config.trigger.before :up do
93-
if !File.exists?(CLOUD_CONFIG_PATH) || File.readlines(CLOUD_CONFIG_PATH).grep(/#\s*discovery:/).any?
93+
if !File.exists?(CLOUD_CONFIG_PATH) || File.readlines(CLOUD_CONFIG_PATH).grep(/\s*discovery #DISCOVERY_URL/).any?
9494
raise Vagrant::Errors::VagrantError.new, "Run 'make discovery-url' first to create user-data."
9595
end
9696
end

contrib/aws/gen-json.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
Description=Prepares the etcd data directory
7474
Requires=media-etcd.mount
7575
After=media-etcd.mount
76-
Before=etcd.service
76+
Before=etcd2.service
7777
[Service]
7878
Type=oneshot
7979
RemainAfterExit=yes
@@ -101,12 +101,13 @@
101101
# are started
102102
data['coreos']['units'] = new_units + data['coreos']['units']
103103

104-
# configure etcd to use its EBS volume
105-
data['coreos']['etcd']['data-dir'] = '/media/etcd'
106-
107104
header = ["#cloud-config", "---"]
108105
dump = yaml.dump(data, default_flow_style=False)
109106

107+
# configure etcd to use its EBS volume
108+
dump = dump.replace('-data-dir /var/lib/etcd2', '-data-dir /media/etcd')
109+
dump = dump.replace('--volume=/var/lib/etcd2', '--volume=/media/etcd')
110+
110111
template = json.load(open(os.path.join(CURR_DIR, 'deis.template.json'), 'r'))
111112

112113
template['Resources']['CoreOSServerLaunchConfig']['Properties']['UserData']['Fn::Base64']['Fn::Join'] = ["\n", header + dump.split("\n")]

contrib/aws/provision-aws-cluster.sh

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,17 +136,29 @@ ELB_NAME=$(aws elb describe-load-balancers \
136136
$EXTRA_AWS_CLI_ARGS | grep -F $ELB_DNS_NAME | head -n1 | cut -f2)
137137
echo "Using ELB $ELB_NAME at $ELB_DNS_NAME"
138138
139-
echo_green "Your Deis cluster has been successfully deployed to AWS CloudFormation and is started."
140-
echo_green "Please continue to follow the instructions in the documentation."
141-
142139
FIRST_INSTANCE=$(aws ec2 describe-instances \
143140
--filters Name=tag:aws:cloudformation:stack-name,Values=$STACK_NAME Name=instance-state-name,Values=running \
144141
--query 'Reservations[].Instances[].[PublicIpAddress]' \
145142
--output text \
146143
$EXTRA_AWS_CLI_ARGS | head -1)
147144
export DEISCTL_TUNNEL=$FIRST_INSTANCE
148-
echo_green "Enabling proxy protocol"
149145
146+
# loop until etcd2 / fleet are up and running
147+
COUNTER=1
148+
until deisctl list >/dev/null; do
149+
if [ $COUNTER -gt $ATTEMPTS ];
150+
then echo_red "Timed out waiting for fleet, giving up"
151+
break
152+
fi
153+
echo "Waiting until fleet is up and running ..."
154+
sleep 5
155+
let COUNTER=COUNTER+1
156+
done
157+
158+
echo_green "Your Deis cluster has been successfully deployed to AWS CloudFormation and is started."
159+
echo_green "Please continue to follow the instructions in the documentation."
160+
161+
echo_green "Enabling proxy protocol"
150162
if ! deisctl config router set proxyProtocol=1; then
151163
echo_red "#"
152164
echo_red "# Enabling proxy protocol failed, please enable proxy protocol "

contrib/azure/azure-coreos-cluster

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ coreos:
6868
addr: $private_ipv4:4001
6969
peer-addr: $private_ipv4:7001
7070
units:
71-
- name: etcd.service
71+
- name: etcd2.service
7272
command: start
7373
- name: fleet.service
7474
command: start

contrib/azure/create-azure-user-data

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def main():
6262
configuration = combine_dicts(configuration_coreos_template,
6363
configuration_azure_template)
6464

65-
configuration["coreos"]["etcd"]["discovery"] = url
65+
configuration["coreos"]["etcd2"]["discovery"] = url
6666

6767
with azure_user_data as outfile:
6868
try:

contrib/coreos/user-data.example

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,6 @@
11
#cloud-config
22
---
33
coreos:
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.
@@ -19,7 +9,41 @@ coreos:
199
etcd_request_timeout: 3.0
2010
units:
2111
- name: etcd.service
12+
mask: true
13+
- name: etcd2.service
2214
command: start
15+
content: |
16+
[Unit]
17+
Description=etcd2 container
18+
Requires=early-docker.service
19+
After=early-docker.service
20+
Before=early-docker.target
21+
22+
[Service]
23+
User=etcd
24+
PermissionsStartOnly=true
25+
Restart=always
26+
RestartSec=10s
27+
EnvironmentFile=/etc/environment
28+
Environment="ETCD_IMAGE=quay.io/coreos/etcd:v2.0.13"
29+
Environment="DOCKER_HOST=unix:///var/run/early-docker.sock"
30+
LimitNOFILE=40000
31+
ExecStartPre=/bin/sh -c "docker history $ETCD_IMAGE >/dev/null 2>&1 || docker pull $ETCD_IMAGE"
32+
ExecStartPre=/bin/sh -c "docker inspect etcd2 >/dev/null 2>&1 && docker rm -f etcd2 || true"
33+
ExecStart=/usr/bin/docker run --net=host --rm \
34+
--volume=/var/lib/etcd2:/var/lib/etcd2 \
35+
--volume=/usr/share/ca-certificates:/etc/ssl/certs:ro \
36+
-p 4001:4001 -p 2380:2380 -p 2379:2379 -p 7001:7001 \
37+
--name etcd2 \
38+
${ETCD_IMAGE} \
39+
-name %m \
40+
-data-dir /var/lib/etcd2 \
41+
-advertise-client-urls http://${COREOS_PRIVATE_IPV4}:2379,http://${COREOS_PRIVATE_IPV4}:4001 \
42+
-listen-client-urls http://0.0.0.0:2379,http://0.0.0.0:4001 \
43+
-initial-advertise-peer-urls http://${COREOS_PRIVATE_IPV4}:2380,http://${COREOS_PRIVATE_IPV4}:7001 \
44+
-listen-peer-urls http://0.0.0.0:2380,http://0.0.0.0:7001 \
45+
--discovery #DISCOVERY_URL
46+
ExecStop=-/usr/bin/docker stop etcd2
2347
- name: docker-tcp.socket
2448
command: start
2549
enable: true
@@ -48,8 +72,8 @@ coreos:
4872
[Unit]
4973
Description=Clean up
5074
DefaultDependencies=no
51-
After=fleet.service etcd.service docker.service docker.socket deis-store-admin.service deis-store-daemon.service deis-store-volume.service deis-store-monitor.service
52-
Requires=fleet.service etcd.service deis-store-admin.service deis-store-daemon.service deis-store-volume.service docker.service docker.socket deis-store-monitor.service
75+
After=fleet.service etcd2.service docker.service docker.socket deis-store-admin.service deis-store-daemon.service deis-store-volume.service deis-store-monitor.service
76+
Requires=fleet.service etcd2.service deis-store-admin.service deis-store-daemon.service deis-store-volume.service docker.service docker.socket deis-store-monitor.service
5377

5478
[Install]
5579
WantedBy=shutdown.target halt.target reboot.target

contrib/gce/create-gce-user-data

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def main():
6262
configuration = combine_dicts(configuration_coreos_template,
6363
configuration_gce_template)
6464

65-
configuration["coreos"]["etcd"]["discovery"] = url
65+
configuration["coreos"]["etcd2"]["discovery"] = url
6666

6767
with gce_user_data as outfile:
6868
try:

contrib/linode/apply-firewall.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def get_discovery_url_from_user_data():
4747
current_dir = os.path.dirname(__file__)
4848
user_data_file = file(os.path.abspath(os.path.join(current_dir, name)), 'r')
4949
user_data = yaml.safe_load(user_data_file)
50-
return user_data['coreos']['etcd']['discovery']
50+
return user_data['coreos']['etcd2']['discovery']
5151
except:
5252
raise IOError('Could not load discovery url from ' + name)
5353

contrib/util/check-user-data.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ function parse_yaml {
2626
}
2727

2828
if [[ $NUM_INSTANCES -ne 1 ]] ; then
29-
parse_yaml $USER_DATA | grep -q coreos_etcd_discovery
30-
if [[ $? -ne 0 ]]; then
29+
parse_yaml $USER_DATA | grep -q "#DISCOVERY_URL"
30+
if [[ $? -ne 1 ]]; then
3131
echo "No etcd discovery URL set in $USER_DATA"
3232
exit 1
3333
fi

0 commit comments

Comments
 (0)