`etcd` is the primary distributed key-value store for all cluster state data of all Kubernetes resources (It's the **source of truth** for a Kubernetes cluster) * When Kubernetes components need to make decisions or update the state of the cluster, they read from and write to `etcd` * Build on the `Raft` consensus algorithm, which ensures that every change made in one node is replicated to the other nodes in the cluster without conflicts * Handles failures of individual nodes and network partitions while maintaining overall system availability and data correctness (*Even if a node fails within the cluster, the service as a whole remains available and consistent*) # Stored Information All registered `worker nodes` and `control plane nodes` ```JSON { "kind": "Node", "metadata": { "name": "NODE_NAME" }, "status": { "capacity": { "cpu": "NUMBER_OF_CPU", "memory": "QUANTITY_OF_MEMORY" } } } ``` Every `Pod` in every `namespace` (Including their status and spec) ```JSON { "kind": "Pod", "metadata": { "name": "POD_NAME", "namespace": "NAMESPACE" }, "spec": { "containers": [{ "name": "NAME", "image": "IMAGE:TAG" }] } } ``` `Deployments` and `ReplicaSets` ```JSON ``` # etcd Operations Install `etcd` ```Bash # ==== Download the latest etcd release ==== ETCD_VER=v3.5.13 # download wget https://github.com/etcd-io/etcd/releases/download/${ETCD_VER}/etcd-${ETCD_VER}-linux-amd64.tar.gz # extract tar -xvf etcd-${ETCD_VER}-linux-amd64.tar.gz # move binaries cd etcd-${ETCD_VER}-linux-amd64 sudo mv etcd etcdctl /usr/local/bin/ # ==== Confirm the install ================= etcd --version etcdctl version ``` Locally run `etcd` ```Bash etcd --name node1 \ --data-dir /var/lib/etcd \ --listen-client-urls http://localhost:2379 \ --advertise-client-urls http://localhost:2379 ``` Test `etcdctl` ```Bash etcdctl --endpoints=http://localhost:2379 put key1 "Hello ETCD" etcdctl --endpoints=http://localhost:2379 get key1