In this article, we will set up an etcd
database in our Kubernetes Cluster. The etcd
database will be responsible for storing the state data of components in our cluster.
Pre-Requisite
- TLS Certificates generated for
etcd
Bootstrapping the etcd
Cluster
Components in Kubernetes are stateless. The cluster state is stored in the etcd
database that is installed in our cluster.
Install etcd
Let's proceed to set up the etcd
database inside our cluster using the instruction(S) provided below.
wget -q --show-progress --https-only --timestamping "https://github.com/coreos/etcd/releases/download/v3.5.3/etcd-v3.5.3-linux-amd64.tar.gz
Now, install the etcd
server and etcdctl
command line utility by using the following commands
tar -xvf etcd-v3.5.3-linux-amd64.tar.gz
sudo mv etcd-v3.5.3-linux-amd64/etcd* /usr/local/bin
Configure etcd
We'll now set up the certificate files we generated in the last article for our etcd
cluster.
Use the commands below to set it up.
Set the ETCD Name
the same as the hostname
of the node it's being installed in.
ETCD_NAME=$(hostname -s)
INTERNAL_IP=$(ip addr show enp0s8 | grep "inet " | awk '{print $2}' | cut -d / -f 1)
MASTER=$(dig +short master)
Each etcd
member must have a unique name within an etcd
cluster. Set the etcd
name to match the hostname
of the specific instance it's running on.
Start etcd
Using a Service
Let's create a service file for etcd
.
vim /etc/systemd/system/etcd.service
Let's start up the etcd
cluster.
Verify the etcd
Cluster Installation
Now, let's verify that the installation was a success.
Success! Our etcd
cluster is functioning as intended.
Frequently Asked Questions:
What is the use of etcd
?
etcd
stores the state of different components in the Kubernetes cluster. The components in the control plane use session data available in etcd
to schedule and remove pods in the cluster.
Why is a stateful workload like etcd
deployed in Kubernetes?
The main drawback of running stateful workloads in Kubernetes is storage. As it was built with stateless workloads in mind, running stateful workloads will present a different set of challenges. However, etcd
stores its data (which is relatively low in size) in memory and runs on the control plane only, so it's suitable for use in Kubernetes.
How can I take backups of my etcd
cluster?
A backup of the etcd
cluster can be taken as:
Example of Backup Command:
Verifying the backup:
Restore etcd
We have the backup in the /opt/backup/etcd.db
location. Now, we will use the snapshot backup to restore etcd
.
Here is the command to restore etcd
:
Let's execute the etcd
restore command. In my case /opt/backup/etcd.db
is the backup file.
If you wish to restore to a specific directory in the cluster, then the --data-dir
flag can be used to achieve it.
Conclusion
In this article, we set up the etcd
database, generated service files and learned to backup
and restore
the etcd
database.
Please comment down below if you have any queries or concerns, this article will be periodically maintained for authenticity!