DevOps, coding & IT infrastructures

What is Consul?

Consul describes itself as "a service networking solution to connect and secure services across any runtime platform and public or private cloud". It brings service discovery, load balancing, health checks and a configurable key-value store.

It is a product of HashiCorp, the company behind Terraform and Vagrant. You can read an introduction and comparisons to other solutions on their webpage.

Installation into Google Kubernetes engine

This part is super-easy. Just go to the Marketplace page of Consule and click on the Configure button. Consul is free to be deployed and you only pay for the usage of Google Kubernetes Engine.

Consul 1-click installation at Google Marketplace

If you want to install Consul via the console, you can check the README.

Local usage of kubectl

Before we can go ahead using kubectl, we need to configure it with the correct credentials:

# Configure gloud
gcloud auth configure-docker

# Set the the correct credentials for kubectl
gcloud container clusters get-credentials cluster-1 --region europe-west1-b

You can now use kubectl to e.g. get a list of all client Pods used by Consul:

(bash) $ kubectl get pods -o wide -l app.kubernetes.io/component=consul-client --namespace default

This should print a list of your Consul pods:

A list of your consul pods

If this brings no results for you, you might need to change the -- namespace parameter to something else.

Getting started with consule CLI

To access the bash of the consulCLI tool, you can connect to any of the listed pods and run the command:

$ kubectl exec -it <name_of_a_pod> --namespace default -- bash
Consul v1.4.5

To make things easier for us, we can setup an alias:

alias consul="kubectl exec -it <name_of_a_pod> --namespace default -- consul"

This way we can just type in consule and it should work.

If you want to list all members / agents of Consul:

(fish) $ consul members
A list of your consul pods

You can also directly connect to the Pod:

(bash) $ kubectl exec -it <name_of_a_pod> --namespace default -- bash

You can now read into the Consul Getting started guide to learn how to register and connect a Service.

Consul UI

You can also check on the UI of Consul. Just follow the following steps:

Open the Services:

A list of your consul pods

Click on consul-test-consul-ui and click on Port forwarding (at the very bottom):

Click on Run in shell:

It copies it to the Shell, you still need to press ENTER for it to run:

Then you can click on the button which appeared next to the last clicked one:

Now you should see the Consul UI:

You can learn more about it following the Tutorial of HashiCorp.

You’ve successfully subscribed to Coding with passion
Welcome back! You’ve successfully signed in.
Great! You’ve successfully signed up.
Success! Your email is updated.
Your link has expired
Success! Check your email for magic link to sign-in.