This is a demo of a much larger experience.
Nomad and Consul Integration Guide
Overview
This guide covers the basic integration between HashiCorp Nomad and Consul for service discovery and health checking.
Prerequisites
- Nomad installed and running
- Consul installed and running
- Both services accessible on your network
Configuration
1. Configure Nomad to Connect to Consul
Add the following to your Nomad configuration file (e.g., nomad.hcl):
consul {
address = "127.0.0.1:8500"
auto_advertise = true
server_auto_join = true
client_auto_join = true
}
2. Basic Job with Service Registration
Create a job file that registers a service with Consul:
job "example" {
datacenters = ["dc1"]
group "web" {
count = 3
task "nginx" {
driver = "docker"
config {
image = "nginx:latest"
port_map {
http = 80
}
}
resources {
network {
port "http" {}
}
}
service {
name = "nginx-web"
port = "http"
tags = [
"web",
"nginx"
]
check {
type = "http"
path = "/"
interval = "10s"
timeout = "2s"
}
}
}
}
}
3. Verify Integration
Check that services are registered in Consul:
consul catalog services
View service details:
consul catalog nodes -service=nginx-web
Key Features
- Automatic Service Registration: Nomad automatically registers services with Consul
- Health Checks: Define health checks that Consul monitors
- Service Discovery: Applications can discover services via Consul DNS or API
- Load Balancing: Use Consul for service mesh capabilities
Common Use Cases
- Service Discovery: Applications query Consul to find service endpoints
- Health Monitoring: Consul tracks service health and removes unhealthy instances
- Dynamic Configuration: Use Consul KV store with Nomad templates
Troubleshooting
- Ensure Consul agent is running:
consul members - Check Nomad-Consul connection:
nomad server members - Verify service registration:
consul catalog services - Review Nomad logs for connection errors
Next Steps
- Explore Consul Connect for service mesh
- Implement Consul KV with Nomad templates
- Set up multi-datacenter configurations