Introduction to ETCD in Kubernetes

At the end of this post you will have:

  • Understood what the ETCD service is in kubernetes.
  • Installed the ETCD service.

We will start with a basic introduction to what a key value store is and how it is different from traditional databases. Later we discuss how to quickly get started with ETCD and how to use the client tool to operate.

So... what is ETCD?

It is a distributed reliable key value store that is simple secure and fast.

What is a key value store?

Traditionally databases have been represented in a tabular format. You must have heard about SQL or relational databases. They store data in the form of rows and columns. For example, here is a table that stores information regarding a few individuals. The row represents each person and the column represents the type of information being stored.

Name Age Location
Kevin Smith 22 California
Rico Suave 26 China
Kelly Nelson 40 Mexico
Logan Patterson 10 Canada
Key Value
Name Kevin Smith
Age 22
Location California
Salary 50,000

Each key refers to a particular value. In this example each key refers to a field in person object which is saved in the database.

You then use this key to retrieve data from the DB in a fast way. You cannot have duplicate keys. As such it is not used as a replacement for a regular tabular database. Instead it is used to store and retrieve small chunks of data such as configuration data that requires fast read and write.

Installing ETCD

It is easy to install and get started with ETCD.

  1. Download the relevant binary for your operating system from the github releases pages. Example Using MacOS:
curl -L https://github.com/etcd-io/etcd/releases/download/${ETCD_VER}/etcd-${ETCD_VER}-darwin-amd64.zip -o /tmp/etcd-${ETCD_VER}-darwin-amd64.zip
unzip /tmp/etcd-${ETCD_VER}-darwin-amd64.zip -d /tmp && rm -f /tmp/etcd-${ETCD_VER}-darwin-amd64.zip
mv /tmp/etcd-${ETCD_VER}-darwin-amd64/* /tmp/etcd-download-test && rm -rf mv /tmp/etcd-${ETCD_VER}-darwin-amd64

Make sure to replace the download url as well as the etcd version as such:

curl -L https://github.com/etcd-io/etcd/releases/download/v3.3.11/etcd-v3.3.11-darwin-amd64.zip -o /tmp/etcd-v3.3.11-darwin-amd64.zip
unzip /tmp/etcd-v3.3.11-darwin-amd64.zip -d /tmp && rm -f /tmp/etcd-v3.3.11-darwin-amd64.zip
mv /tmp/etcd-v3.3.11-darwin-amd64/* /tmp/etcd-download-test && rm -rf mv /tmp/etcd-v3.3.11-darwin-amd64
  1. Extract:
tar xzvf etcd-v3.3.11-linux-amd64.tar.gz
  1. Run ETCD Service:
./etcd

For more information about installation visit the full installation guide

When you run ETCD, it starts a service that listens on port 2379 by default.

You can then attach any clients to the ETCD service to store and retrieve information. By default, the client that comes with ETCD is the ETCD control client which is a command line client that you can use to store and retrieve key value pairs.

To store a key value pair run:

./etcdctl set key1 value1

This creates an entry in the database with the information.

To retrieve the stored data run:

./etcdctl get key1

To see more command options, run:

./etcdctl

That was a quick introduction to ETCD.

Later in this series we will discuss more about configuring ETCD customers in a high availability setup and the best practices around it.