HashiCorp Certified: Consul Associate Certification
Register Services and Use Service Discovery
Check Service Status from the Catalog
With services and health checks registered in Consul, you can verify which nodes are healthy using three primary interfaces:
Interface | Description | Example Command |
---|---|---|
DNS | Resolve name.service.consul via DNS lookup | dig @10.0.3.45 -p 8600 front-end-eCommerce.service.consul |
API | Query Consul’s HTTP API for service entries | curl http://10.0.3.45:8500/v1/catalog/service/my-service |
UI | Browse the Consul web interface | Open http://<consul-server>:8500/ui in your browser |
In the sections below, we’ll walk through each method step by step.
1. DNS Queries
Using DNS is often the simplest way to discover services in Consul, since most applications already support DNS resolution.
How It Works
- Your corporate DNS forwards queries for the
.consul
domain to Consul’s DNS port (8600). - The application looks up
database.service.consul
as an A record. - Consul responds with the IP addresses of healthy service instances.
- The application selects an IP and connects to the service.
Note
Ensure your firewall allows traffic to port 8600/udp
for DNS forwarding.
Example: dig
against Consul DNS
dig @10.0.3.45 -p 8600 front-end-eCommerce.service.consul
Sample output:
; <<>> DiG 9.10.6 <<>> @10.0.3.45 -p 8600 front-end-eCommerce.service.consul
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR
;; QUESTION SECTION:
;front-end-eCommerce.service.consul. IN A
;; ANSWER SECTION:
front-end-eCommerce.service.consul. 0 IN A 10.3.15.67
...
;; SERVER: 10.0.3.45#8600(10.0.3.45)
Consul returned the healthy instance at 10.3.15.67
.
2. API Requests
When your application can make HTTP requests, the Consul HTTP API lets you retrieve service entries in JSON format.
Steps
- Send a GET request to:
http://<consul-server>:8500/v1/catalog/service/<service-name>
- Consul returns a JSON array of nodes passing health checks.
- Your code parses the array and picks an IP to connect.
Example: curl
against the Catalog API
curl --request GET http://10.0.3.45:8500/v1/catalog/service/front-end-eCommerce
Sample JSON response:
[
{
"Node": "web-server-01",
"Address": "10.3.15.67",
"ServiceName": "front-end-eCommerce",
"ServiceTags": ["v7.05","production"]
}
]
Here, only 10.3.15.67
is healthy.
3. Consul UI
For human operators, the Consul web UI offers an intuitive overview of services and checks.
- Open your browser at
http://<consul-server>:8500/ui
. - Click Services in the sidebar to list all registered services.
- Select a service (e.g., customer-database-ecommerce) to view node details, health status, tags, and metadata.
Warning
The Consul UI is unauthenticated by default. Consider enabling ACLs or reverse-proxy authentication in production.
With DNS queries, REST API calls, and the web UI, you have flexible options to check service status in Consul’s catalog and ensure your applications connect to healthy nodes.
Links and References
Watch Video
Watch video content