What is ETCD?
In this tutorial, we will discuss what is ETCD? ETCD is a distributed, reliable key-value store that is simple, secure and Fast. It is used to hold and manage the critical information that distributed systems need to keep running. It most commonly manages the configuration data, state data, and metadata for Kubernetes, the popular container orchestration platform.
Etcd allows clients to subscribe to changes to a particular key or set of keys.
What is Key-Value store
Traditionally databases have been in a tabular form. You must have heard about SQL or relational databases. They stored data in the form of rows and columns. For example
In the above table, the row represents each person, and the column represents the type of information. Now you want to add additional details like salary; then we need to add the extra column.
But here some persons are not working (for example students). So here, some cells are empty. Now you want to add a grade column for students, so you need to add a new column to the existing table.
Now again, only students have grades and empty cells for employees. Every time new information is added, the entire table is affected and leads to many empty cells.
Now avoid such problems, the key-value store was introduced. Key-value stores store information in the form of documents or pages. So each individual gets a document, and all information about that individual store within that file. These files can be any format or structure, and changes to one file don’t affect another.
ETCD installation is very simple
1. Download Binaries
curl -L https://github.com/etcd-io/etcd/releases/download/v3.4.13/etcd-v3.4.13-linux-amd64.tar.gz -o /tmp/etcd-v3.4.13-linux-amd64.tar.gz
tar -xvzf /tmp/etcd-v3.4.13-linux-amd64.tar.gz
3. RUN ETCD Service
When you run the etcd, it starts a service that listens on port 2379 by default. You can then attach clients to an etcd service to store and retrieve information. The default client that comes with etcd is an etcdctl client.
To set information
./etcdctl set key1 value1
To get information
./etcdctl get key1 value1
ETCD in Kubernetes
The ETCD data store stores information regarding the cluster such as Nodes, PODs, Config, Secrets, Accounts, Roles, Bindings and Others. Every change you make in the cluster, such as adding additional nodes, deploying pods, replica sets, are updated in this data store.
Only once it is updated in the ETCD server is the change considered to be complete. Depending on how you set up your cluster, ETCD is deployed differently.
Raft consensus algorithm
etcd is built on the Raft consensus algorithm to ensure data store consistency across all nodes in a cluster—table stakes for a fault-tolerant distributed system.
Raft achieves this consistency via an elected leader node that manages replication for the other nodes in the cluster, called followers. The leader accepts requests from the clients, which it then forwards to follower nodes.
Once the leader has ascertained that most follower nodes have stored each new request as a log entry, it applies the entry to its local state machine and returns the result of that execution—a ‘write’—to the client. If followers crash or network packets are lost, the leader retries until all followers have stored all log entries consistently.
If a follower node fails to receive a message from the leader within a specified time interval, an election is held to choose a new leader. The follower declares itself a candidate, and the other followers vote for it or any other node based on its availability.
Once the new leader is elected, it begins managing replication, and the process repeats itself. This process enables all etcd nodes to maintain highly available, consistently replicated copies of the data store.