-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigure.sh
executable file
·91 lines (78 loc) · 2.27 KB
/
configure.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/bin/bash
exec > /tmp/configure.log 2>&1
ETCDCTL_BASE="etcdctl \
--ca-file /etc/ssl/5pi-ca.pem \
--cert-file /etc/ssl/server.pem \
--key-file /etc/ssl/server-key.pem"
ETCDCTL="$ETCDCTL_BASE --endpoints https://$(hostname):2379"
# First fix permissions, no matter what. See hashicorp/terraform#8811
chmod 640 /etc/ssl/server-key.pem
chown :k8s /etc/ssl/server-key.pem
set -euo pipefail
. /etc/environment.tf
# Add servers to /etc/hosts
for ((i=0;i<SERVERS;i++)); do
echo "${IP_INT_PREFIX}.$i.1 master$i"
done >> /etc/hosts
# Enable swap
fallocate -l 4G /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
if ! grep /swapfile /etc/fstab; then
echo '/swapfile none swap sw 0 0' >> /etc/fstab
fi
# Bring up tinc
systemctl enable tinc@default
systemctl start tinc@default
# Calculate IP_INT
IP_INT="${IP_INT_PREFIX}.${INDEX}.1"
# Configuring etcd
ETCD_SERVERS=
ETCD_SERVERS_OTHER=
CLUSTER=
for ((i=0;i<SERVERS;i++)); do
ETCD_SERVERS="https://master$i:2379,$ETCD_SERVERS"
CLUSTER="master$i=https://${IP_INT_PREFIX}.$i.1:2380,$CLUSTER"
if [[ "$i" -ne "$INDEX" ]]; then
ETCD_SERVERS_OTHER="https://master$i:2379,$ETCD_SERVERS_OTHER"
fi
done
case "$STATE" in
new)
ETCD_OPTS="--initial-cluster-state new --initial-cluster $CLUSTER --initial-advertise-peer-urls https://$IP_INT:2380"
;;
existing)
ETCD_OPTS="--initial-cluster-state existing --initial-cluster $CLUSTER"
;;
*)
echo "State $STATE is invalid, aborting" >&2
exit 1
esac
cat <<EOF > /etc/environment.calc
ETCD_OPTS='$ETCD_OPTS'
ETCD_SERVERS='$ETCD_SERVERS'
IP_INT='$IP_INT'
EOF
# Enabling services here, so they don't come up unconfigured
for s in etcd k8s-apiserver k8s-controller-manager \
k8s-kubelet k8s-proxy k8s-scheduler docker node_exporter; do
systemctl enable "$s"
systemctl start "$s" --no-block
done
if [[ "$STATE" == "new" ]]; then
exit 0
fi
# Add ourself to the existing cluster
while ! $ETCDCTL_BASE --endpoints $ETCD_SERVERS_OTHER member add master$INDEX "https://$IP_INT:2380"; do
echo "Waiting for existing cluster to be reachable"
sleep 1
done
# Waiting for things to be ready
if [ "$STATE" = "existing" ]; then
while ! $ETCDCTL cluster-health; do
echo "Waiting for cluster to become healthy"
sleep 1
done
fi
kubectl uncordon master$INDEX