ETCD

ETCD is a distributed reliable key-value store that is simple, secure & Fast. The ETCD Datastore stores information regarding the cluster such as Nodes, PODS, Configs, Secrets, Accounts, Roles, Bindings and Others. Every information you see when you run the kubectl get command is from the ETCD Server.

[manual] Install etcd

Its easy to install and get started with ETCD.

Download the relevant binary for your operating system from github releases page (https://github.com/etcd-io/etcd/releases)

# For Example: To download ETCD V3.3.11, run the below curl command
$ wget -q --https-only "https://github.com/etcd-io/etcd/releases/download/v3.3.11/etcd-v3.3.11-linux-amd64.tar.gz"

Extract it.

$ tar xvzf etcd-v3.3.11-linux-amd64.tar.gz

Run the ETCD Service

$ ./etcd

When you start ETCD it will by default listens on port 2379. The default client that comes with ETCD is the etcdctl client. You can use it to store and retrieve key-value pairs.

# Syntax: To Store a Key-Value pair
$ ./etcdctl set key1 value1
# Syntax: To retrieve the stored data
$ ./etcdctl get key1
# Syntax: To view more commands. Run etcdctl without any arguments
$ ./etcdctl

image-20210808234208528

image-20210808235610728

[kubeadm] Install etcd

If you setup your cluster using kubeadm then kubeadm will deploy etcd server for you as a pod in kube-system namespace.

$ kubectl get pods -n kube-system

image-20210808235700716

Explore ETCD

To list all keys stored by Kubernetes, run the below command

$ kubectl exec etcd-master -n kube-system etcdctl get / --prefix -key

image-20210809002214396

ETC in HA Environment

  • In a high availability environment, you will have multiple master nodes in your cluster that will have multiple ETCD Instances spread across the master nodes.
  • Make sure etcd instances know each other by setting the right parameter in the etcd.service configuration. The --initial-cluster option where you need to specify the different instances of the etcd service.

image-20210809002351967

ETCD Commands

For example ETCDCTL version 2 supports the following commands:

etcdctl backup
etcdctl cluster-health
etcdctl mk
etcdctl mkdir
etcdctl set

Whereas the commands are different in version 3

etcdctl snapshot save
etcdctl endpoint health
etcdctl getetcdctl put

To set the right version of API set the environment variable ETCDCTL_API command

export ETCDCTL_API=3