paint-brush
Setting up an etcd cluster on AWS using CoreOS & Terraformby@mlabouardy
2,704 reads
2,704 reads

Setting up an etcd cluster on AWS using CoreOS & Terraform

by Mohamed LabouardyNovember 5th, 2017
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

This post is part of “<a href="http://www.blog.labouardy.com/manage-aws-vpc-as-infrastructure-as-code-with-terraform/" target="_blank"><strong>IaC</strong></a>” series explaining how to use <strong>Infrastracture as Code</strong> concepts with <strong>Terraform</strong>. In this part, I will show you how to setup an <strong>etcd</strong> cluster on <strong>AWS</strong> using <strong>CoreOS </strong>&amp; <strong>Terraform</strong> as shown in the diagram below&nbsp;:

Companies Mentioned

Mention Thumbnail
Mention Thumbnail
featured image - Setting up an etcd cluster on AWS using CoreOS & Terraform
Mohamed Labouardy HackerNoon profile picture

This post is part of “IaC” series explaining how to use Infrastracture as Code concepts with Terraform. In this part, I will show you how to setup an etcd cluster on AWS using CoreOS & Terraform as shown in the diagram below :

All the templates used in this demo can be found on my Github.

So let’s start with “variables.tf” file which contains the global variables such as AWS region, cluster instances type …

Note: As of writing this article, the latest stable CoreOS version is 1465.6.0.

So make sure to find an AMI that is as close to the latest version as possible.

Next, we need to define a security group for our cluster. For simplicity, Im going to make this security group open to the world. Even though security is important, this tutorial serves an educational purposes and you should never have all ports open in production.

And finally, we will define our cluster which consists of 3 Nodes:

In order to bring up an etcd cluster, I used a cloud config file that I passed as a parameter to user_data attribut:

Note: Make sure to grab the discovery token, and place it into the discovery parameter:

$ curl https://discovery.etcd.io/new?size=3

https://discovery.etcd.io/3e86b59982e49066c5d813af1c2e2579cbf573de

Once you defined all templates required, just type the following command to bring up the etcd cluster:

terraform apply

Note: Don’t forget to set the AWS credentials as an envrionment variables before:

export AWS_ACCESS_KEY_ID=”YOUR ACCESS KEY ID”

export AWS_SECRET_ACCESS_KEY=”YOUR SECRET ACCESS KEY”

Setting up an etcd cluster in action is shown below:

Once done, go to your AWS Management Console then navigate to your EC2 Dashboard:

Congratulations ! You have your CoreOS cluster.

To verify the cluster health, you can either point your browser to the discovery url you generated earlier:

or SSH to one of your cluster nodes using the command:

ssh core@<NODE-IP>

Then, use the etcd command line to fetch the cluster status:

Now we have an etcd cluster ready to use. Let’s see what we can do with it:

  • Through etcdctl:

etcdctl set nginx/port 80

etcdctl get nginx/port 80

etcdctl ls nginx

etcdctl rm nginx/port

  • Through HTTP API:

curl -sS -X PUT -d value=”80" http://localhost:2379/v2/keys/nginx/port | jq ‘.’ # Create

curl -sS http://localhost:2379/v2/keys/nginx/port | jq ‘.’ # Get

curl -sS -X DELETE http://localhost:2379/v2/keys/nginx/port | jq ‘.’ # Delete