2016-07-07 18:06:53 +03:00
|
|
|
# Bootstrapping a H/A etcd cluster
|
2016-07-07 17:15:59 +03:00
|
|
|
|
2016-07-07 18:06:53 +03:00
|
|
|
In this lab you will bootstrap a 3 node etcd cluster. The following virtual machines will be used:
|
2016-07-07 17:15:59 +03:00
|
|
|
|
2016-07-08 20:26:32 +03:00
|
|
|
```
|
|
|
|
gcloud compute instances list
|
|
|
|
```
|
|
|
|
|
2016-07-07 18:06:53 +03:00
|
|
|
````
|
2016-07-08 20:26:32 +03:00
|
|
|
NAME ZONE MACHINE_TYPE PREEMPTIBLE INTERNAL_IP EXTERNAL_IP STATUS
|
|
|
|
etcd0 us-central1-f n1-standard-1 10.240.0.10 XXX.XXX.XXX.XXX RUNNING
|
|
|
|
etcd1 us-central1-f n1-standard-1 10.240.0.11 XXX.XXX.XXX.XXX RUNNING
|
|
|
|
etcd2 us-central1-f n1-standard-1 10.240.0.12 XXX.XXX.XXX.XXX RUNNING
|
2016-07-07 18:06:53 +03:00
|
|
|
````
|
|
|
|
|
2016-07-07 18:25:27 +03:00
|
|
|
## Why
|
|
|
|
|
|
|
|
All Kubernetes components are stateless which greatly simplifies managing a Kubernetes cluster. All state is stored
|
|
|
|
in etcd, which is a database and must be treated special. etcd is being run on a dedicated set of machines for the
|
|
|
|
following reasons:
|
|
|
|
|
|
|
|
* The etcd lifecycle is not tied to Kubernetes. We should be able to upgrade etcd independently of Kubernetes.
|
|
|
|
* Scaling out etcd is different than scaling out the Kubernetes Control Plane.
|
|
|
|
* Prevent other applications from taking up resources (CPU, Memory, I/O) required by etcd.
|
|
|
|
|
2016-07-07 18:06:53 +03:00
|
|
|
## Provision the etcd Cluster
|
2016-07-07 17:15:59 +03:00
|
|
|
|
2016-07-08 20:26:32 +03:00
|
|
|
Run the following commands on `etcd0`, `etcd1`, `etcd2`:
|
2016-07-07 17:15:59 +03:00
|
|
|
|
2016-07-08 20:26:32 +03:00
|
|
|
> SSH into each machine using the `gcloud compute ssh` command
|
2016-07-07 17:15:59 +03:00
|
|
|
|
2016-07-07 18:06:53 +03:00
|
|
|
Move the TLS certificates in place:
|
2016-07-07 17:15:59 +03:00
|
|
|
|
|
|
|
```
|
|
|
|
sudo mkdir -p /etc/etcd/
|
|
|
|
```
|
|
|
|
|
|
|
|
```
|
|
|
|
sudo mv ca.pem kubernetes-key.pem kubernetes.pem /etc/etcd/
|
|
|
|
```
|
|
|
|
|
2016-07-07 18:06:53 +03:00
|
|
|
Download and install the etcd binaries:
|
|
|
|
|
2016-07-07 17:15:59 +03:00
|
|
|
```
|
|
|
|
wget https://github.com/coreos/etcd/releases/download/v3.0.1/etcd-v3.0.1-linux-amd64.tar.gz
|
|
|
|
```
|
|
|
|
|
|
|
|
```
|
|
|
|
tar -xvf etcd-v3.0.1-linux-amd64.tar.gz
|
|
|
|
```
|
|
|
|
|
|
|
|
```
|
2016-07-09 03:16:08 +03:00
|
|
|
sudo cp etcd-v3.0.1-linux-amd64/etcd* /usr/bin/
|
2016-07-07 17:15:59 +03:00
|
|
|
```
|
|
|
|
|
|
|
|
```
|
|
|
|
sudo mkdir -p /var/lib/etcd
|
|
|
|
```
|
|
|
|
|
2016-07-07 18:06:53 +03:00
|
|
|
Create the etcd systemd unit file:
|
|
|
|
|
2016-07-08 20:26:32 +03:00
|
|
|
|
2016-07-07 17:15:59 +03:00
|
|
|
```
|
2016-07-08 20:26:32 +03:00
|
|
|
cat > etcd.service <<"EOF"
|
|
|
|
[Unit]
|
2016-07-07 17:15:59 +03:00
|
|
|
Description=etcd
|
|
|
|
Documentation=https://github.com/coreos
|
|
|
|
|
|
|
|
[Service]
|
2016-07-08 20:26:32 +03:00
|
|
|
ExecStart=/usr/bin/etcd --name ETCD_NAME \
|
2016-07-07 17:15:59 +03:00
|
|
|
--cert-file=/etc/etcd/kubernetes.pem \
|
|
|
|
--key-file=/etc/etcd/kubernetes-key.pem \
|
|
|
|
--peer-cert-file=/etc/etcd/kubernetes.pem \
|
|
|
|
--peer-key-file=/etc/etcd/kubernetes-key.pem \
|
|
|
|
--trusted-ca-file=/etc/etcd/ca.pem \
|
|
|
|
--peer-trusted-ca-file=/etc/etcd/ca.pem \
|
2016-07-08 20:26:32 +03:00
|
|
|
--initial-advertise-peer-urls https://INTERNAL_IP:2380 \
|
|
|
|
--listen-peer-urls https://INTERNAL_IP:2380 \
|
|
|
|
--listen-client-urls https://INTERNAL_IP:2379,http://127.0.0.1:2379 \
|
|
|
|
--advertise-client-urls https://INTERNAL_IP:2379 \
|
2016-07-07 17:15:59 +03:00
|
|
|
--initial-cluster-token etcd-cluster-0 \
|
|
|
|
--initial-cluster etcd0=https://10.240.0.10:2380,etcd1=https://10.240.0.11:2380,etcd2=https://10.240.0.12:2380 \
|
|
|
|
--initial-cluster-state new \
|
|
|
|
--data-dir=/var/lib/etcd
|
|
|
|
Restart=on-failure
|
|
|
|
RestartSec=5
|
|
|
|
|
|
|
|
[Install]
|
2016-07-08 20:26:32 +03:00
|
|
|
WantedBy=multi-user.target
|
|
|
|
EOF
|
2016-07-07 17:15:59 +03:00
|
|
|
```
|
|
|
|
|
|
|
|
```
|
2016-07-08 20:26:32 +03:00
|
|
|
export INTERNAL_IP=$(curl -s -H "Metadata-Flavor: Google" \
|
|
|
|
http://metadata.google.internal/computeMetadata/v1/instance/network-interfaces/0/ip)
|
2016-07-07 17:15:59 +03:00
|
|
|
```
|
|
|
|
|
|
|
|
```
|
2016-07-08 20:26:32 +03:00
|
|
|
export ETCD_NAME=$(hostname -s)
|
2016-07-07 17:15:59 +03:00
|
|
|
```
|
|
|
|
|
|
|
|
```
|
2016-07-08 20:26:32 +03:00
|
|
|
sed -i s/INTERNAL_IP/$INTERNAL_IP/g etcd.service
|
2016-07-07 17:15:59 +03:00
|
|
|
```
|
|
|
|
|
|
|
|
```
|
2016-07-08 20:26:32 +03:00
|
|
|
sed -i s/ETCD_NAME/$ETCD_NAME/g etcd.service
|
2016-07-07 17:15:59 +03:00
|
|
|
```
|
|
|
|
|
|
|
|
```
|
2016-07-08 20:26:32 +03:00
|
|
|
sudo mv etcd.service /etc/systemd/system/
|
2016-07-07 17:15:59 +03:00
|
|
|
```
|
|
|
|
|
2016-07-07 18:06:53 +03:00
|
|
|
Start etcd:
|
|
|
|
|
2016-07-07 17:15:59 +03:00
|
|
|
```
|
|
|
|
sudo systemctl daemon-reload
|
|
|
|
sudo systemctl enable etcd
|
|
|
|
sudo systemctl start etcd
|
|
|
|
```
|
|
|
|
|
2016-07-09 03:14:11 +03:00
|
|
|
|
2016-07-08 20:26:32 +03:00
|
|
|
### Verification
|
2016-07-07 17:15:59 +03:00
|
|
|
|
|
|
|
```
|
2016-07-08 20:26:32 +03:00
|
|
|
sudo systemctl status etcd --no-pager
|
2016-07-07 17:15:59 +03:00
|
|
|
```
|
|
|
|
|
2016-07-09 03:14:31 +03:00
|
|
|
> Remember to run these steps on `etcd0`, `etcd1`, and `etcd2`
|
|
|
|
|
2016-07-08 20:26:32 +03:00
|
|
|
## Verification
|
2016-07-07 18:06:53 +03:00
|
|
|
|
2016-07-08 20:26:32 +03:00
|
|
|
Once all 3 etcd nodes have been bootstrapped verify the etcd cluster is healthy:
|
2016-07-07 17:15:59 +03:00
|
|
|
|
|
|
|
```
|
2016-07-08 20:26:32 +03:00
|
|
|
gcloud compute ssh etcd0
|
2016-07-07 17:15:59 +03:00
|
|
|
```
|
|
|
|
|
|
|
|
```
|
|
|
|
etcdctl --ca-file=/etc/etcd/ca.pem cluster-health
|
|
|
|
```
|
|
|
|
|
|
|
|
```
|
|
|
|
member 3a57933972cb5131 is healthy: got healthy result from https://10.240.0.12:2379
|
|
|
|
member f98dc20bce6225a0 is healthy: got healthy result from https://10.240.0.10:2379
|
|
|
|
member ffed16798470cab5 is healthy: got healthy result from https://10.240.0.11:2379
|
|
|
|
cluster is healthy
|
|
|
|
```
|