Back to articles
AI & Cloud

Guide to Configure etcd Cluster on 3 Cheap Vultr VPS - Sustainable Distributed Infrastructure State Backup Solution

Detailed guide to configure a 3-node etcd cluster on cheap Vultr VPS for ensuring data integrity and system recovery in distributed infrastructure. Includes setup, configuration,...

DPTCloud Engineering4 min read
Guide to Configure etcd Cluster on 3 Cheap Vultr VPS - Sustainable Distributed Infrastructure State Backup Solution

Introduction to etcd and Its Role in Distributed Infrastructure

etcd is a distributed, consistent, and highly reliable key-value store designed to manage configuration data, service state, and locks in distributed systems. It is a core component of Kubernetes, storing the entire cluster state, including pods, services, configurations, and deployment status.

In distributed environments, ensuring data integrity and system resilience is critical. A 3-node etcd cluster provides high availability and fault tolerance through data synchronization and leader election mechanisms.

Deploying etcd on 3 affordable Vultr VPS is a cost-effective solution that still ensures system reliability. This guide provides a detailed walkthrough of configuring a 3-node etcd cluster on Vultr VPS with Ubuntu 22.04.

Requirements and Environment Preparation

To deploy an etcd cluster, you need:

  • 3 Vultr VPS with Ubuntu 22.04 (minimum 2GB RAM, 2 vCPU)
  • Static IP addresses for each VPS (public or private)
  • etcd version 3.5 or higher
  • etcdctl for cluster management and testing
  • SSH access to each VPS

Note: The following IPs are examples. Replace them with your actual VPS IPs.

  • VPS 1: 104.248.123.101
  • VPS 2: 104.248.123.102
  • VPS 3: 104.248.123.103

Configuring the etcd Cluster

Perform the following steps on each VPS.

1. Install etcd

On each VPS, run the following commands to install etcd:

wget https://github.com/etcd-io/etcd/releases/download/v3.5.12/etcd-v3.5.12-linux-amd64.tar.gz
tar -xzf etcd-v3.5.12-linux-amd64.tar.gz
sudo mv etcd-v3.5.12-linux-amd64/etcd* /usr/local/bin/
sudo mkdir -p /var/lib/etcd
sudo chmod 755 /var/lib/etcd

2. Create etcd Configuration

Create the etcd configuration file at /etc/etcd/etcd.conf with the following content (adjust ETCD_NAME, ETCD_DATA_DIR, ETCD_LISTEN_CLIENT_URLS, ETCD_ADVERTISE_CLIENT_URLS, ETCD_INITIAL_ADVERTISE_PEER_URLS, ETCD_INITIAL_CLUSTER, and ETCD_INITIAL_CLUSTER_STATE for each VPS):

ETCD_NAME=etcd-1
ETCD_DATA_DIR=/var/lib/etcd
ETCD_LISTEN_CLIENT_URLS=http://0.0.0.0:2379
ETCD_ADVERTISE_CLIENT_URLS=http://104.248.123.101:2379
ETCD_LISTEN_PEER_URLS=http://0.0.0.0:2380
ETCD_ADVERTISE_PEER_URLS=http://104.248.123.101:2380
ETCD_INITIAL_ADVERTISE_PEER_URLS=http://104.248.123.101:2380
ETCD_INITIAL_CLUSTER=etcd-1=http://104.248.123.101:2380,etcd-2=http://104.248.123.102:2380,etcd-3=http://104.248.123.103:2380
ETCD_INITIAL_CLUSTER_STATE=new
ETCD_INITIAL_CLUSTER_TOKEN=etcd-cluster-1
ETCD_CERT_DIR=/etc/etcd

Repeat for VPS 2 and VPS 3, adjusting ETCD_NAME and IP addresses accordingly.

3. Start etcd

Create a systemd service file to start etcd automatically:

sudo tee /etc/systemd/system/etcd.service <<EOF
[Unit]
Description=etcd
After=network.target

[Service]
Type=notify
User=etcd
ExecStart=/usr/local/bin/etcd --config-file=/etc/etcd/etcd.conf
Restart=on-failure
LimitNOFILE=65536

[Install]
WantedBy=multi-user.target
EOF

Start and enable the service:

sudo systemctl daemon-reload
sudo systemctl enable etcd
sudo systemctl start etcd

Testing and Verifying the Cluster

After starting etcd on all three VPS instances, verify the cluster status using the following command:

ETCDCTL_API=3 etcdctl --endpoints=http://104.248.123.101:2379,http://104.248.123.102:2379,http://104.248.123.103:2379 member list

The output should list all three nodes in the cluster with a status of \"started\".

State Backup Solution for Distributed Infrastructure

To ensure data integrity, perform regular backups of the etcd state. Use the following command to save a snapshot:

ETCDCTL_API=3 etcdctl --endpoints=http://104.248.123.101:2379,http://104.248.123.102:2379,http://104.248.123.103:2379 snapshot save /tmp/etcd-snapshot.db

To restore from a backup:

ETCDCTL_API=3 etcdctl --endpoints=http://104.248.123.101:2379 snapshot restore /tmp/etcd-snapshot.db --data-dir=/var/lib/etcd/snapshot-restored

Change the data-dir to a new directory, then restart etcd.

Troubleshooting and Notes

  • Ensure ports 2379 (client) and 2380 (peer) are not blocked by firewalls.
  • Only modify ETCD_INITIAL_CLUSTER and ETCD_INITIAL_CLUSTER_STATE when creating a new cluster. Do not change them if the cluster is already running.
  • Do not start etcd multiple times on the same machine with the same ETCD_NAME.
  • Ensure system time is synchronized across all VPS instances (use NTP).

References

Related infrastructure & engineering guides: High-RAM Cloud VPS for Self-Hosted LLMs & API Gateways

DPTCloud Tier III Infrastructure

High-RAM Cloud VPS Plans Optimized for AI, Databases & Cache

Enterprise RAID 10 NVMe SSDs, CMC & FPT District 9 uplinks with Anycast Anti-DDoS and 99.99% SLA.

View 22 VPS Plans
ECO · vn-02Recommended

VPS-4E

297.000 ₫ / mo

10% VAT included

  • CPU: 4 vCPU
  • RAM: 8 GB
  • SSD: 50 GB NVMe
ECO · vn-02

VPS-5E

614.900 ₫ / mo

10% VAT included

  • CPU: 8 vCPU
  • RAM: 16 GB
  • SSD: 100 GB NVMe
ADVANCED · vn-03Recommended

VPS-4T

548.900 ₫ / mo

10% VAT included

  • CPU: 4 vCPU
  • RAM: 8 GB
  • SSD: 50 GB NVMe

Related Articles

View all
ZaloZalo SupportDiscord0384 753 478