Consul is an important service discovery tool in the world of Devops. This tutorial covers in-depth working knowledge of Consul, its setup and deployment. This tutorial aims to help new userβs setup consul, develop advanced knowledge on consul and learn some interesting projects built around consul. In the end, I hope the readers understand this tutorial and use consul for their daily work. This tutorial will give you a quick start with Consul and make you comfortable with its various components.
Audience
This tutorial is prepared for the students, beginners as well as for intermediate Devops Practitioners to help them understand the basics to advanced concepts related to the Consul tool.
Prerequisites
Before you start doing practice with the examples given in this tutorial, it is being assumed that you already have a basic knowledge of Linux, Git, Golang, Docker and AWS (Amazon Web Services).
Introduction
Consul is a tool for discovering and configuring a variety of different services in your infrastructure. It is based and built on Golang. One of the core reasons to build Consul was to maintain the services present in the distributed systems. Some of the significant features that Consul provides are as follows.
- Service Discovery β Using either DNS or HTTP, applications can easily find the services they depend upon.
- Health Check Status β It can provide any number of health checks. It is used by the service discovery components to route traffic away from unhealthy hosts.
- Key/Value Store β It can make use of Consul’s hierarchical key/value store for any number of purposes, including dynamic configuration, feature flagging, coordination, leader election, etc.
- Multi Datacenter Deployment β Consul supports multiple datacenters. It is used for building additional layers of abstraction to grow to multiple regions.
- Web UI β Consul provides its users a beautiful web interface using which it can be easy to use and manage all of the features in consul.
Service Discovery
Service discovery is one of the most important feature of Consul. It is defined as the detection of different services and network protocols using which a service is found. The usage of service discovery comes in as a boon for distributed systems. This is one of the main problems, which are faced by today’s large-scale industries with the advancement of distributed systems in their environment.
Comparison with Etcd and Zookeeper
When we look at other service discovery tools in this domain, we have two popular options. Some major players in the software industry have been using it in the past. These tools are Etcd and Zookeeper.
Let us consider the following table for comparing different aspects of each tool. We will also understand what each one of them uses internally.
Properties | Consul | Etcd | Zoo Keeper |
---|---|---|---|
User Interface | Available | ||
RPC | Available | Available | |
Health Check | HTTP API | HTTP API | TCP |
Key Value | 3 Consistency modes | Good Consistency | Strong Consistency |
Token System | Available | ||
Language | Golang | Golang | Java |
Consul – Members and Agents
Consul members can be defined as the list of different agents and server modes using which a consul cluster is deployed. Consul provides us with a command line feature using which we can easily list all the agents associated with consul.
Consul agent is the core process of Consul. The agent maintains membership information, registers services, runs checks, responds to queries, etc. Any agent can be run in one of two modes: Client or Server. These two modes can be used according to their role as decided when using consul. The consul agent helps by providing us information, which is listed below.
- Node name β This is the hostname of the machine.
- Datacenter β The datacenter in which the agent is configured to run. Each node must be configured to report to its datacenter.
- Server β It indicates whether the agent is running in server or client mode. Server nodes participates in the consensus quorum, storing cluster state and handling queries.
- Client Addr β It is the address used for client interfaces by the agent. It includes the ports for the HTTP, DNS, and RPC interfaces.
- Cluster Addr β It is the address and the set of ports used for communication between Consul Agents in a cluster. This address must be reachable by all other nodes.
In the next chapter, we will understand the architecture for Consul.