On-Prem k8s | Part 5

Bootstrapping etcd Cluster

Kubernetes stores cluster states in an etcd k/v store. We will now setup a three nodes etcd cluster for high availability.

Install binaries

wget -q --show-progress --https-only --timestamping \

Extract and copy etcd and etcdctl binaries to your PATH

tar -xvf etcd-v3.2.18-linux-amd64.tar.gz
sudo mv etcd-v3.2.18-linux-amd64/etcd* /usr/local/bin

Setup etcd

Create etcd directories and copy TLS certs

sudo mkdir -p /etc/etcd /var/lib/etcd
sudo cp ca.pem kubernetes-key.pem kubernetes.pem /etc/etcd/

Each etcd node needs a unique name. We will use the hostname as name:

ETCD_NAME=`hostname -s`

We also need to specify the IP address we will bind etcd to:

IP=`nslookup $(hostname -s) | awk '/^Address: / { print $2 }'`

Create the systemd unit file for etcd service

cat > etcd.service <<EOF

ExecStart=/usr/local/bin/etcd \\
  --name ${ETCD_NAME} \\
  --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 \\
  --peer-client-cert-auth \\
  --client-cert-auth \\
  --initial-advertise-peer-urls https://${IP}:2380 \\
  --listen-peer-urls https://${IP}:2380 \\
  --listen-client-urls https://${IP}:2379, \\
  --advertise-client-urls https://${IP}:2379 \\
  --initial-cluster-token etcd-cluster-0 \\
  --initial-cluster k8sctl1=,k8sctl2=,k8sctl3= \\
  --initial-cluster-state new \\


Bootstratp etcd cluster

Enable and start the etcd service:

sudo mv etcd.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable etcd
sudo systemctl start etcd

Check etcd cluster is up and running

List the etcd cluster members:

ETCDCTL_API=3 etcdctl member list


b826932a88befba, started, k8sctl1,,
203a99ec1242917c, started, k8sctl2,,
4fb9793032518ec9, started, k8sctl3,,

Next: Bootstrapping k8s Control Plane >

< Previous: Generating the Data Encryption Config

  • Category
comments powered by Disqus