A Practical Guide To HashiCorp Consul — Part 2

What are we Building?

Example Application nodes and services deployed on them

How Does Consul Come into the Picture?

Setup: MongoDB, Django, Consul, Fabio, and Dockerization

MongoDB

Django

  • ENGINE: The database connector to use for Django ORM.
  • NAME: Name of the database.
  • HOST: Host address that has MongoDB running on it.
  • PORT: Which port is your MongoDB listening for requests.

Consul

Consul on nodes running MongoDB Replica Set

Consul on nodes running Django App

Consul Server

Fabio

Dockerization

Dockerizing MongoDB Replica Set along with Consul Agent

Dockerizing Django Web Application along with Consul Agent

Dockerizing Consul Server

Docker Compose

Service Discovery using Consul

Consul Web UI showing the set of services we are running and their current state
Fabio auto-detecting the Django Web Application end-points
Django Web Application renders the MongoDB connection status on the home page
Django Web Application services as seen on Consul’s Web UI
MongoDB Replica Set Primary service as seen on Consul’s Web UI
MongoDB Replica Set Secondary services as seen on Consul’s Web UI
MongoDB Primary service being swapped with one of the MongoDB Secondary instances
MongoDB Secondary instance set is now left with only one service instance
Switching off the MongoDB Primary is also reflected in the Django Web Application
Failing MongoDB Primary service instance is now cleared out from service instances as it is now healthy MongoDB Secondary service instance
Previously failed MongoDB Primary service instance is now re-adopted as MongoDB Secondary service instance as it has become healthy again
Fabio is able to auto-configure itself using Consul’s service registry and detecting alive service instances

Service Configuration using Consul

Consul KV store as seen on Consul Web UI with Django app configuration parameters

Service Segmentation using Consul

Define access control for services via Connect and service connection restrictions

Conclusion

References

--

--

Thoughts and ideas on startups, enterprise software & technology by the Velotio team. Learn more at www.velotio.com.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Velotio Technologies

Velotio Technologies is an outsourced software and product development partner for technology startups & enterprises. #Cloud #DevOps #ML #UI #DataEngineering