Skip to content

Commit f164208

Browse files
committed
use binary release of etcd for etcd servers
1 parent fcd3797 commit f164208

File tree

6 files changed

+80
-12
lines changed

6 files changed

+80
-12
lines changed

kubernetes.tf

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ resource "template_file" "kubernetes" {
9898
containers_cidr = "${var.containers_cidr}"
9999
kubernetes_version = "${var.kubernetes_version}"
100100
portal_net = "${var.portal_net}"
101+
etcd_version = "${var.etcd_version}"
101102
}
102103
}
103104

@@ -131,8 +132,8 @@ resource "aws_instance" "etcd" {
131132

132133

133134
provisioner "file" {
134-
source = "scripts/${self.tags.Role}.sh"
135-
destination = "/tmp/${self.tags.Role}.sh"
135+
source = "scripts"
136+
destination = "/tmp/scripts"
136137
}
137138

138139
provisioner "remote-exec" {
@@ -142,10 +143,11 @@ resource "aws_instance" "etcd" {
142143
"sudo mv /tmp/network.env /etc/network.env",
143144
"cat <<'EOF' > /tmp/kubernetes.env\n${template_file.kubernetes.rendered}\nEOF",
144145
"sudo mv /tmp/kubernetes.env /etc/kubernetes.env",
145-
"sudo bash /tmp/${self.tags.Role}.sh"
146+
"sudo bash /tmp/scripts/${self.tags.Role}.sh"
146147
]
147148
}
148149
}
150+
149151
resource "aws_instance" "master" {
150152
ami = "${var.ami}"
151153
instance_type = "t2.medium"
@@ -236,4 +238,3 @@ output "kubernetes-api-server" {
236238
value = "${template_file.kubectl-config.rendered}"
237239
}
238240

239-

scripts/etcd.sh

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@ set -x
55
source /etc/kubernetes.env
66
source /etc/network.env
77

8+
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
89

9-
start() {
10-
systemctl daemon-reload
11-
systemctl enable ${1}.service
12-
systemctl start ${1}.service
13-
}
10+
source $DIR/functions.sh
1411

12+
setup-install-etcd
1513

1614
cat <<EOF > /etc/etcd.env
1715
ETCD_LISTEN_CLIENT_URLS=http://0.0.0.0:2379
@@ -20,12 +18,26 @@ ETCD_INITIAL_ADVERTISE_PEER_URLS=http://${PRIVATE_IP}:2380
2018
ETCD_ADVERTISE_CLIENT_URLS=http://${PRIVATE_IP}:2379
2119
EOF
2220

23-
mkdir -p /etc/systemd/system/etcd2.service.d
24-
cat <<EOF > /etc/systemd/system/etcd2.service.d/50-etcd.conf
21+
cat <<'EOF' > /etc/systemd/system/etcd.service
22+
[Unit]
23+
Description=etcd
24+
2525
[Service]
2626
EnvironmentFile=/etc/kubernetes.env
2727
EnvironmentFile=/etc/etcd.env
28+
Environment=ETCD_DATA_DIR=/var/lib/etcd2
29+
Environment=ETCD_NAME=%m
30+
User=etcd
31+
PermissionsStartOnly=true
32+
ExecStartPre=/opt/bin/install-etcd
33+
ExecStart=/opt/bin/etcd
34+
Restart=always
35+
RestartSec=10s
36+
LimitNOFILE=40000
37+
38+
[Install]
39+
WantedBy=multi-user.target
2840
EOF
2941

30-
start etcd2
42+
start etcd
3143

scripts/functions.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
3+
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
4+
5+
6+
enable() {
7+
systemctl daemon-reload
8+
systemctl enable ${1}.service
9+
}
10+
11+
start() {
12+
systemctl daemon-reload
13+
systemctl enable ${1}.service
14+
systemctl start ${1}.service
15+
}
16+
17+
setup-install-etcd() {
18+
mkdir -p /opt/bin
19+
cp $DIR/install-etcd /opt/bin/install-etcd
20+
chmod +x /opt/bin/install-etcd
21+
}
22+

scripts/install-etcd

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
set -e
3+
source /etc/kubernetes.env
4+
5+
if [ -f /opt/etcd-${ETCD_BINARY_VERSION}/bin/etcd ]; then
6+
exit 0
7+
fi
8+
9+
cd /tmp
10+
11+
if [ ! -f etcd-${ETCD_BINARY_VERSION}.tar.gz ]; then
12+
curl -o etcd-${ETCD_BINARY_VERSION}.tar.gz -L -s https://github.com/coreos/etcd/releases/download/v2.0.11/etcd-v2.0.11-linux-amd64.tar.gz
13+
fi
14+
15+
mkdir -p /opt/etcd-${ETCD_BINARY_VERSION}/bin
16+
17+
tar -zxf etcd-${ETCD_BINARY_VERSION}.tar.gz
18+
cp etcd-v${ETCD_BINARY_VERSION}-linux-amd64/{etcd,etcdctl} /opt/etcd-${ETCD_BINARY_VERSION}/bin
19+
20+
chmod -R 755 /opt/etcd-${ETCD_BINARY_VERSION}/bin
21+
22+
mkdir -p /opt/bin
23+
for P in /opt/etcd-${ETCD_BINARY_VERSION}/bin/*; do
24+
ln -sf $P /opt/bin/
25+
done
26+
27+

templates/kubernetes.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ KUBERNETES_CONTAINERS_CIDR="${containers_cidr}"
22
KUBERNETES_VERSION="${kubernetes_version}"
33
KUBERNETES_PORTAL_NET="${portal_net}"
44
ETCD_DISCOVERY="${etcd_dicovery_url}"
5+
ETCD_BINARY_VERSION="${etcd_version}"

variables.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,8 @@ variable "ami" {
3737
variable "kubernetes_version" {
3838
default = "0.17.1"
3939
}
40+
41+
variable "etcd_version" {
42+
description = "version of etcd to use"
43+
default = "2.0.11"
44+
}

0 commit comments

Comments
 (0)