This demonstration showcases a simplified implementation of Nomad and Consul for service deployment and discovery. It utilizes a single machine for both Nomad server and client, as well as Consul server and client. Two Docker images are leveraged: a web-frontend built with React and a Node.js backend, both retrieved from Docker Hub. Separate Nomad jobs are defined for the frontend, backend, and an Nginx service for load balancing. Consul acts as the service registry, allowing the Nginx job to discover the frontend and backend services within the Nomad cluster. This setup provides a basic example of how Nomad and Consul can be used to manage and orchestrate containerized applications.
- Understanding Containerization (Docker)
- Service Orchestration Fundamentals (Kubernetes)
- Basic Networking Knowledge
-
Download and Install Nomad:
- Visit the Nomad download page.
- Choose the appropriate package for your system and follow the installation instructions.
-
Check Nomad Version:
nomad version
-
Download and Install Consul:
- Visit the Consul download page.
- Choose the appropriate package for your system and follow the installation instructions.
-
Check Consul Version:
consul version
-
Run Nomad Client Agent:
cd nomad && nohup sudo nomad agent -config client.hcl &
-
Run Nomad Server Agent:
cd nomad && nohup sudo nomad agent -config server.hcl &
- Run Consul Dev Agent:
nohup consul agent -dev -client 0.0.0.0 &
- Submit Jobs to Nomad:
- Submit the frontend-website(ReactJS) job to Nomad:
sudo nomad run frontend.nomad.hcl
- Submit the backend-website(NodeJS) job to Nomad: (Wait a few seconds for the above job to become healthy before running the next command.)
sudo nomad run backend.nomad.hcl
- Submit the nginx job to Nomad: (Wait a few seconds for the above job to become healthy before running the next command.)
sudo nomad run nginx.nomad.hcl
Cheers! 🎉 You can now access your deployed website.
To access the website:
- On a cloud instance (AWS/Azure/GCP): open your browser and enter http:https://public-ip:8080
- On a local machine: open your browser and enter http:https://localhost:8088
- Accessing the Nomad Web UI:
http:https://localhost:4646
- Registering a Job:
nomad job run example.nomad.hcl
- Displays the status of all registered jobs:
nomad job status
- Inspecting a Specific Job:
nomad job status
- Stop a Nomad Job:
nomad job stop -purge <job-name>
- Listing Allocations:
nomad alloc status
- Inspecting a Specific Allocation:
nomad alloc status <alloc-id>
- Viewing Logs for a Job:
nomad job logs <job-name>
- Viewing Logs for an Allocation:
nomad alloc logs <alloc-id>
- List Nomad Processes:
ps aux | grep nomad
- Kill Nomad Processe:
sudo killall nomad
- Accessing the Consul Web UI:
http:https://localhost:8500
- Leave/Stop the Consul Cluster:
consul leave
- Display Consul Status and Metrics:
consul info
- View Members in the Cluster:
consul members
- List Services Registered with Consul::
consul catalog services
- List Nodes for a Specific Service:
consul catalog nodes -service=<service_name>
- Check Consul Version:
consul version
HashiCorp provides excellent documentation for both
• Nomad https://developer.hashicorp.com/nomad and
• Consul https://developer.hashicorp.com/consul/docs.
These resources are a great starting point to learn about their features and configuration options.