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

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

Common Use Cases

  1. Service Discovery: Applications query Consul to find service endpoints
  2. Health Monitoring: Consul tracks service health and removes unhealthy instances
  3. Dynamic Configuration: Use Consul KV store with Nomad templates

Troubleshooting

Next Steps