How To Setup a etcd Cluster On Linux – Beginners Guide

Introduction

etcd is an open source key-value store for storing and retrieving configurations. It is a core component in Kubernetes to store and retrieve objects state information. It works in a leader-member fashion by making the etcd clusters highly available to withstand node failures.

    1. Its a distributed key-value store
    2. It uses raft protocol
    3. Clients can use REST/gRPC to retrieve the stored values.

Prerequisites

Before you begin, make sure you have the following setup.

  1. Three Linux servers (Can be an odd quorum of 5, 7 etc based on the needs)
  2. A valid hostname for all the servers
  3. Firewall rules enabled all the servers on following ports for client requests and peer to peer communication.

Setup an etcd Cluster on Linux

etcd setup is fairly easy and this guide follows the static bootstrap method, which means you need to know the IPs of your nodes for bootstrapping. This guide covers all the necessary steps to set up a cluster on Linux servers. It is a multinode setup with systemd files to run etcd as a service.

Following are the etcd server hostname and IP details used in this guide. Change the IPs mentioned in the guide with your IPs where ever needed.

  1. etcd-1: 10.128.0.2
  2. etcd-2: 10.128.0.4
  3. etcd-3: 10.128.0.3

Let’s get started with the setup.

On All the 3 Nodes

Perform steps 1 to 6 on all the three nodes.

Step 1: CD into local src folder

Step 2: Download the latest etcd release from the etcd Github Releases. At the time of writing this article, the latest version is 3.3.10

Step 3: Untar the binary.

Step 4: Move the extracted etcd executables (etcd & ectdctl) to local bin.

Step 5: Create relevant etcd folders, user & group. We will be running the etcd service as an etcd user.

Step 6: Perform the following as root user.

Set two environment variables. One to fetch the system IP and another to get the system hostname.

Create a systemd service file for etcd. Replace --listen-client-urls with your server IPs

Note: –name , –initial-advertise-peer-urls, –listen-peer-urls, –listen-client-urls will be different for each server. ETCD_NAME & ETCD_HOST_IP variables will automatically replace it.

Bootstrap The etcd Cluster

Once all the configurations are applied on the three servers, start and enable the newly created etcd service on all the nodes. The first server will act as a bootstrap node. One node will be automatically elected as a leader once the service is started in all the three nodes.

Verify etcd Cluster Status

ectdctl is the utility to interact with the etcd cluster. You can find this utility in the folder/usr/local/bin of all the nodes.

You can use any one of the cluster nodes to perform the following checks.

Check the cluster health using the following command

Verify cluster membership status using the following command. It will show the leader status.

By default, etcdctl uses etcd v2. So you need to explicitly use a variable ETCDCTL_API=3 to access etcd v3 functionalities.

You can set it as an environment variable or pass it along with each etcdctl command as shown below.

Let’s write few key-value pairs in the cluster and verify it.

Now you can try getting the value of name3 using the following command.

You can list all the keys using ranges and prefixes

 

READ  How To Integrate and Visualize Prometheus Metrics In Grafana

Free DevOps Resources

Get DevOps news, tutorials and resources in your inbox. A perfect way If you want to get started with devops. Like you, we dont like spam.