Skip to content

Instantly share code, notes, and snippets.

@vincentramirez
Last active March 27, 2019 11:11
Show Gist options
  • Save vincentramirez/84ea815b466a0d302f02f69e0a72cf30 to your computer and use it in GitHub Desktop.
Save vincentramirez/84ea815b466a0d302f02f69e0a72cf30 to your computer and use it in GitHub Desktop.
HashiCorp Consul Learn Lab01

This is a guide to supliment the https://learn.hashicorp.com/consul/ content

You will be given a list of IP address that you can use for the lab exercises

To access the vm's you will need the IP address and a copy of the private key your instructure created

On your local system perform the following

cd /tmp
mkdir keys
cd /tmp/keys
vi lab_rsa
press i
copy past the public key text shared with you
press esc key
:wq! enter
chmod 400 lab_rsa

You can now ssh into your vms

*This step assumes you are still in the dir /tmp/keys created in the previous step

ssh -i ./lab_rsa ubuntu@<yourVMipAddr>

Repeat as need for multiple sessions, or to connect to other lab vm's

Install Consul

This should be performed on all of your lab vm's

ssh -i ./lab_rsa ubuntu@<yourVMpublicIpAddr>
cd /tmp
wget https://releases.hashicorp.com/consul/1.4.4/consul_1.4.4_linux_amd64.zip
sudo apt install unzip -y
unzip consul_1.4.4_linux_amd64.zip
sudo chmod +x consul
sudo mv consul /usr/bin/consul
sudo mkdir /etc/consul.d
sudo chmod a+w /etc/consul.d

Test the install

consul version

Bootstrap your consul server

*This step is to be performed by at least 3 members of the class on separate VMs
While logged into your server

consul agent -server -bootstrap-expect=3 \
-data-dir=/tmp/consul -node=server-<yourFirstName> -bind=<yourPrivateIP> \
-enable-script-checks=true -config-dir=/etc/consul.d -ui

Open a new ssh session back into your VM and verify Consul members

consul members

At this point you should only see yourself

*Optionally a 4th student can bootstrap a server as a client member

consul agent -data-dir=/tmp/consul -node=agent-<yourFirstName> \
-bind=<yourPrivateIP> -enable-script-checks=true -config-dir=/etc/consul.d -ui

Join your server into a Consul cluster with your neighboring students

consul join <privateIPofNeighbor>

Verify the number of Consul members

consul members

Enter some kv data

Each student should enter some kv data

consul kv put <firstName> <lastName>
consul kv get <firstName>

Simulate a Consul server failure

2 of the students that have a Consul agent running in server mode perform this step, one at a time and observe the behavior

First Student- in an ssh session back into your VM

pkill -9 consul

Observe what happens in your ssh session that was used to start the Consul agent in a previous step
*Have a student that DID NOT kill their consul service run

consul kv get <firstName>

Second Student- in an ssh session back into your VM

pkill -9 consul

Observe what happens in your ssh session that was used to start the Consul agent in a previous step
*Have a student that DID NOT kill their consul service run

consul kv get <firstName>

What happens?

Start Consul servers to restore cluster

First and Second students return to their ssh session that was used to bootstrap their Consul server
up arrow to show the bootstrap command and press enter
Each student can now run

consul members
consul kv get <firstName>

What happens?

Clean up

Close out all ssh windows. Instructor will destroy lab VMs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment