Getting Started with Consul Service Mesh for Virtual Machines
This tutorial installs and configures Consul service mesh on virtual machines running Linux.
By the end of this tutorial, you will be able to identify the installation prerequisites, provision a Consul server, and deploy an example workload with Consul clients and proxies.
Note
The virtual machines in this demonstration do not use the production reference architecture.
Prerequisites
Install VirtualBox for your machine. You will create 5 Linux machines, each using Ubuntu 18.04, 1 CPU, and 512 MB of memory.
Validate you have vagrant
installed.
Validate you have consul
installed.
Clone the demo configuration and application.
Change directory to use the demo configuration and application.
Deploy Consul
To deploy Consul service mesh, you need a control plane for the service mesh.
Review the Consul server configuration at config/consul-server.hcl
. It sets up
one Consul server, enables the Consul UI, and enables Consul's service mesh features.
The configuration also sets the protocol for services to HTTP and exposes proxy
metrics by default.
Use Vagrant to deploy a Consul server pre-configured with a demo instance of Prometheus for metrics.
Vagrant port forwards requests to the Consul server on port 8500. As a result, you can use the
Consul CLI to check Consul on http://localhost:8500 without need to
set an environment variable for CONSUL_HTTP_ADDR
. Validate the installation by checking for
the running Consul server using consul members
.
To access the Consul UI, go to http://localhost:8500 in your browser. Explore the Consul UI by examining the Nodes and Services tabs.
Deploy a demo application
You can explore Consul service mesh by installing a demo application. The demo application, named HashiCups, includes a set of three services and a PostgreSQL database. It allows you to order a cup of coffee.
Note
In this tutorial, you will not deploy the payments service or Redis to reduce resource requirements.
Each virtual machine installs its own Consul client and proxy. The Consul client configures a proxy on the virtual machine. The proxies create a data plane to handle requests between services based on configuration from Consul.
Review scripts/consul-client.sh
, which Vagrant runs for each machine.
It copies configuration files for the Consul client and the service.
When the Consul client starts, it uses the configuration
files to start a client and register the service.
Use Vagrant to provision the database and three services. On a modern machine with 16GB of RAM, this takes about 10 minutes to complete.
While Vagrant deploys the services, review our video for a brief introduction to Consul.
Validate the installation by checking for the running Consul clients using the Consul CLI.
Explore the application
You can now explore the demo application and how it uses Consul service mesh.
Vagrant port forwards requests to the frontend
virtual machine on port 8000.
Access the frontend
service at http://localhost:8000 in
your browser. Refresh the page a few times.
Go to the Consul UI on http://localhost:8500. You'll find the HashiCups services registered to Consul service mesh with proxies.
Select the product-api
service. The Topology tab indicates that requests to
the public-api
goes to the product-api
before accessing the database.
Consul embeds a graph aggregating successful requests and error metrics.
Clean up
When you finish exploring the deployment, remove Consul and HashiCups from your machine.
Next steps
In this tutorial, you configured Consul service mesh on virtual machines using Vagrant. You also deployed an example application to explore the service topology and track requests.
For a detailed explanation of Consul service mesh, review our tutorial explaining its design and features.
Learn more about using Consul on virtual machines in the following tutorials: