DEV Community

Cover image for How Kubernetes Uses Etcd?
Mansoor Ahmed
Mansoor Ahmed

Posted on

How Kubernetes Uses Etcd?

Introduction
How Kubernetes Uses Eted? Kubernetes is an open-source container arrangement system. This system was developed for programming computer application deployment, scaling, and management. This was first designed by Google and is now sustained by the Cloud Native Computing Foundation. The entire object which we create by Pods, Replication Controllers, Services, Secrets, and so on require being stored someplace in a persistent manner. Therefore is that their displays survive API server restarts and failures. Kubernetes uses etcd for this as this is a fast, distributed, and consistent key-value store. We can run more than one etcd example to deliver together high availability and better performance because it’s distributed.

Description
The Kubernetes API server is the only component that talks to etcd straight. Entire other components read and write data to etcd indirectly over the API server. This takes a few benefits among them like;

A more healthy optimistic locking system along with validation
By removing away the actual storage mechanism from all the other components
It’s far simpler to change it in the future.
Its cost highlighting that etcd is the only place Kubernetes stores cluster state and metadata.

How to operate etcd clusters for Kubernetes
We need to have a Kubernetes cluster, and the kubectl command-line tool must be configured to communicate with our cluster. We may create one by using minikube and can use one of these Kubernetes playgrounds if we do not previously have a cluster:

Katacoda
Play with Kubernetes

To check the version, enter kubectl version

Requirements
Execute etcd as a cluster of odd members.
etcd is a front-runner distributed system. Make sure that the forerunner periodically leads heartbeats on time to all groups to keep the cluster stable.
Make sure that no resource starvation occurs.
Presentation and stability of the cluster is complex to network. It is also sensitive to disk IN and Out. Some resource starvation may lead to heartbeat timeout, producing uncertainty of the cluster. One unbalanced etcd directs that no leader is elected. Further down such conditions, a cluster cannot create any alterations to its current state that suggests no new pods can be scheduled.
Custody of etcd clusters steady is dangerous to the strength of Kubernetes clusters. For that reason, run etcd clusters on steadfast machines or remote environments for certain resource requirements.
The least optional version of etcd to run in production is 3.2.10+.

How resources are stored in etcd?
Resource requirements

Functioning etcd with incomplete resources is appropriate only for testing purposes. An advanced hardware configuration is required for deploying in production. Look resource need position earlier deploying etcd in production.

Beginning etcd clusters
Single-node etcd cluster
We may use a single-node etcd cluster only for testing purpose.

  1. Run the following:

etcd –listen-client-urls=http://$PRIVATE_IP:2379
advertise-client-urls=http://$PRIVATE_IP:2379
Set up an etcd cluster.
Configure a load balancer in the lead of the etcd cluster. E.g., let the address of the load balancer be $LB.
Begin Kubernetes API Servers by the flag –etcd-servers=$LB: 2379.

  1. Start the Kubernetes API server by the flag –etcd-servers=$PRIVATE_IP:2379.

Ensure PRIVATE_IP is set to our etcd client IP.
Multi-node etcd cluster

Run etcd as a multi-node cluster in production and back it up periodically for strength and high availability. A five-member cluster is suggested in production. Design an etcd cluster whichever by static member information or by dynamic discovery. For instance, think through a five-member etcd cluster running with the following client URLs:

http://$IP1:2379, http://$IP2:2379, http://$IP3:2379, http://$IP4:2379, and http://$IP5:2379. To start a Kubernetes API server:

  1. Run the following:

etcd –listen-client-urls=http://$IP1:2379,http://$IP2:2379,http://$IP3:2379,http://$IP4:2379,http://$IP5:2379 –advertise-client-urls=http://$IP1:2379,http://$IP2:2379,http://$IP3:2379,http://$IP4:2379,http://$IP5:2379

  1. Start the Kubernetes API servers with the flag –etcd servers=$IP1:2379,$IP2:2379,$IP3:2379,$IP4:2379,$IP5:2379.

Ensure the IP variables are set to our client IP addresses
Multi-node etcd cluster with load balancer
For running a load balancing etcd cluster:

Securing etcd clusters

Right to use to etcd is corresponding to root consent in the cluster so preferably only the API server should have access to it. It is mentioned to award consent to only those nodes that require access to etcd clusters bearing in mind the sensitivity of the data.

Either one set up firewall rules or use the security features provided by etcd to protect etcd. Its security types depend on x509 Public Key Infrastructure (PKI). Found secure communication channels by creating a key and certificate pair to begin. For instance, use key pair peer.Key and peer.cert for safeguarding communication between etcd members, and client.key and client.cert for make safe communication between etcd and its clients.
For more details visit:https://www.technologiesinindustry4.com/2021/07/how-kubernetes-uses-etcdhtml

Discussion (0)