Kubernetes is the most widely used container orchestration platform. Its popularity is earned by its open-source nature and its robust community support. However, using Kubernetes can be a challenging task. There are many specifications and configurations you need to learn to use this orchestration tool. One of the most important aspects to learn is Kubernetes etcd.

Understanding the purpose of etcd and how to use it is a basic requirement of operating Kubernetes in a production environment. In this article, you’ll learn what etcd is and how it works. You’ll also learn how etcd is used in Kubernetes and some methods of managing it.

Recommended Read: The (in)complete Guide To DOCKER FOR LINUX

Also Read: Informative guide to Gitlab tutorial for Beginners

 

What Is etcd?

etcd is an open-source, persistent, distributed key-value store. It fully replicates data across distributed systems and ensures consistency, security, speed, and availability of resources.

A key-value store is a type of NoSQL database that forms the basis of many distributed systems. It is similar to a relational database and enables you to store unique identifiers (keys) and associated data (values) in individual documents.

The difference between etcd and a relational database is that you can scale etcd more easily since documents are not dependent on each other. Key-value pairs can be used by a single document or by many and updates and additions don’t affect unrelated documents.

Etcd typically operates as a cluster of nodes that communicate via the Raft algorithm. You can see this animation for a visual explanation of how the Raft algorithm works. This algorithm manages the existence of a single node leader. A node leader directs follower nodes and ensures that all nodes in the cluster contain consistent information.

At any given time, your etcd cluster either contains a node leader or is in the process of selecting a new leader. If your cluster is not able to elect a leader, you will not be able to make changes to your database until the cluster is recreated.

 

The Role of etcd in Kubernetes

Kubernetes etcd is a master component that you use as a data store for Kubernetes resource operation data. It serves as a distributed database and a backend for service delivery. Etcd manages the requirements for running a distributed database, such as networking and leader assignment, so Kubernetes doesn’t have to.

You use etcd to replicate and store the states of your clusters. This storage includes cluster status, configuration, and specifications. It also includes both the actual and desired states of your Kubernetes deployment. Your etcd deployment shares this information with nodes so that your cluster is maintained according to your specifications.

 

Using etcd in Kubernetes

You can run etcd as either a pod on your master or in an external cluster. When you run etcd as an external cluster, it is isolated from the master. This isolation can provide you an extra layer of resilience and security. These benefits make cluster deployment the preferred method.

When setting up your clusters, make sure to include an odd number of members; preferably three or five. If you create an even number your cluster will not be able to efficiently select a leader. You should not make your cluster larger than five nodes. It will be more complicated to orchestrate and provide no significant benefits.

To use etcd in production deployments, you need to:

    • Install etcd binaries on your host —etcd v3 is the currently preferred version because v2 support was dropped in Kubernetes v1.13.0.
  • Define your runtime parameters—you should not use autoscaling for your etcd cluster. You can, however, set it to scale up from three to five if you need more reliability.
    • Maintain an up-to-date list of members—this list comes from an external source, such as an infrastructure API or an administrator.
  • Periodically back up your etcd state—etcd natively supports snapshots for backup. You can also use snapshot services offered by your cloud provider, such as AWS or Azure snapshots.

 

Tools for Deploying and Managing etcd Clusters

There are three methods commonly used to deploy and manage your etcd cluster — etcadm, etcdctl, and direct API control.

 

etcadm

etcdadm is an open-source, command-line tool you can use to operate your etcd cluster. It is designed to make the operation of etcd clusters easier by supporting easy deployment, recovery from quorum loss, and scaling.

You can use etcdadm to:

  • Download and install etcd releases
  • Create new clusters from snapshots
  • Generate certificates
  • Add or remove members through the etcd API
  • Verify the health of members

Limitations of etcdadm are that it must run as root since it creates a systemd service, and that it does not support etcd v2. systemd is a tool in Linux that initializes and manages services. For specifics of how to operate etcd using etcadm, you can see this video demonstration. 

 

etcdctl

etcdtl is an open-source, command-line tool you can use to control etcd clusters and operations. It is designed for use in administrative scripts. etcdctl supports the use of etcd v2 and up.

You can use etcdctl to:

  • Configure your cluster
  • Modify, retrieve, and monitor key values
  • Specify your etcd endpoint
  • Use DNS discovery

 

Direct API

Both etcadm and etcdctl use the Direct API but you can also use it directly. To access the API, you can use an HTTP/JSON client, such as cURL. From within the cluster, the location you should use is typically 127.0.0.1 and port 4001.

 

Conclusion

The ability to understand and work with Kubernetes etcd is vital for anyone managing a Kubernetes deployment. Without etcd you cannot store your Kubernetes configurations or automate your deployments.

Hopefully, this article helped you understand what etcd is and what role it plays in your Kubernetes deployment. To make use of etcd, your next step should be to familiarize yourself with the etcd documentation. The documentation provides API specifics and an operations guide that can help with cluster deployment and operation.

Best compression software for Linux

--------------------

Author Bio

Gilad David Maayan is a technology writer who has worked with over 150 technology companies including SAP, Samsung NEXT, NetApp and Imperva, producing technical and thought leadership content that elucidates technical solutions for developers and IT leadership.

LinkedIn: https://www.linkedin.com/in/giladdavidmaayan/

If you think we have helped you or just want to support us, please consider these:-

Connect to us: Facebook | Twitter

Linux TechLab is thankful for your continued support.