ETCD in Kubernetes
- Take me to Video Tutorial
In this section, we will take a look at ETCD role in kubernetes
ETCD Datastore
- The ETCD Datastore stores information regarding the cluster such as
Nodes,PODS,Configs,Secrets,Accounts,Roles,BindingsandOthers. - Every information you see when you run the
kubectl getcommand is from theETCD Server.
Setup - Manual
-
If you setup your cluster from scratch then you deploy
ETCDby downloading ETCD Binaries yourself -
Installing Binaries and Configuring ETCD as a service in your master node yourself.
$ wget -q --https-only "https://github.com/etcd-io/etcd/releases/download/v3.3.11/etcd-v3.3.11-linux-amd64.tar.gz"
Setup - Kubeadm
- If you setup your cluster using
kubeadmthen kubeadm will deploy etcd server for you as a pod inkube-systemnamespace.$ kubectl get pods -n kube-system
Explore ETCD
-
To list all keys stored by kubernetes, run the below command
$ kubectl exec etcd-master -n kube-system -- sh -c "ETCDCTL_API=3 etcdctl --cert=/etc/kubernetes/pki/etcd/server.crt --key=/etc/kubernetes/pki/etcd/server.key --cacert=/etc/kubernetes/pki/etcd/ca.crt get / --prefix --keys-only" -
Kubernetes Stores data in a specific directory structure, the root directory is the
registryand under that you have various kubernetes constructs such asminions,nodes,pods,replicasets,deployments,roles,secretsandOthers.
ETCD 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.serviceconfiguration. The--initial-clusteroption where you need to specify the different instances of the etcd service.
K8s Reference Docs:
- https://kubernetes.io/docs/tasks/administer-cluster/configure-upgrade-etcd/
- https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/setup-ha-etcd-with-kubeadm/
- https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/high-availability/#stacked-control-plane-and-etcd-nodes
- https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/high-availability/#external-etcd-nodes