- Register a basic Consul service
- Add a TCP health check on port 80
- Observe and interpret the service’s health status in the Consul UI
Prerequisites
You need a running Consul agent and an Apache HTTP server on your node.
Registering a Basic Consul Service
First, create a minimal service definition and register it with Consul.The basic service definition offers no health checks, so Consul assumes it is always healthy.
Adding a TCP Health Check
To ensure only healthy instances are returned by service discovery, update the definition to include a TCP health check on port 80. Save the following asservice-with-health.json:
Until the first TCP check passes, Consul marks the service as failing and will not return it in discovery queries.
Observing Health Check Status
- Open the Consul UI.
- Look for the front-end-eCommerce entry under Services.
- If the check is still pending or failing, you’ll see a red “X” icon.
localhost:80. A successful connection flips the status to passing, indicated by a green checkmark.
Simulating Failure and Recovery
To test Consul’s failure detection:| Check Name | Status | Output |
|---|---|---|
| Check web on port 80 | failed | dial tcp 127.0.0.1:80: connect: connection refused |
| Serf Health Status | passing | Agent alive and reachable |
Service Definition Comparison
| Feature | Basic Definition | With TCP Health Check |
|---|---|---|
check block | Not present | Present with tcp, interval, timeout |
| Initial health status | Always passing | Marked failing until first check |
| Service discoverability | Immediate | Delayed until healthy |