1. Interpreting a Service Registration
Every service registration file or API call includes several fields that tell Consul how to manage your service:- ID: A unique identifier (defaults to the service name if not set).
- Name: Logical service name used for discovery.
- Tags: Custom labels for grouping or routing.
- Port: Listening port of your service.
- Address: Optional IP address (otherwise uses the agent’s IP).
- Checks: Health check definitions (see next section).
A well-structured registration makes automated tooling and monitoring far easier to implement.
2. Registering a Service
You have three primary options to register a new service:After adding or modifying a file in the config directory, always run
consul reload to apply changes without downtime.3. Adding Health Checks
Health checks ensure Consul only routes traffic to healthy instances. Common check types:- HTTP
- TCP
- Script
4. Querying the Service Catalog
Verify your services and their health status using:5. Prepared Queries & Failover
Prepared queries let you define advanced routing and failover rules:- Create a Prepared Query
- Define Failover Strategy
Include multiple service pools with weights or priorities. - Execute via API or DNS
- HTTP:
GET /v1/query/{query_id}/execute - DNS:
dig @127.0.0.1 -p 8600 {query_name}.query.consul SRV
- HTTP: