DEV Community

Alex Spinov
Alex Spinov

Posted on

Consul Has a Free API — Service Discovery and Mesh for Any Infrastructure

Consul: Service Discovery That Works Everywhere

HashiCorp Consul provides service discovery, health checking, KV store, and service mesh. Works on Kubernetes, VMs, bare metal, and multi-cloud — unlike K8s-only solutions.

Why Consul

  • Service discovery across any platform
  • Health checking with auto-deregistration
  • Key-value store for config
  • Service mesh with mTLS
  • Multi-datacenter by design

The Free API

# Register a service
curl -X PUT http://localhost:8500/v1/agent/service/register \
  -d "{\"Name\": \"web\", \"Port\": 8080, \"Check\": {\"HTTP\": \"http://localhost:8080/health\", \"Interval\": \"10s\"}}"

# Discover services
curl http://localhost:8500/v1/catalog/service/web

# Health check
curl http://localhost:8500/v1/health/service/web?passing=true

# KV store
curl -X PUT http://localhost:8500/v1/kv/config/db-host -d "postgres.example.com"
curl http://localhost:8500/v1/kv/config/db-host?raw

# List all services
curl http://localhost:8500/v1/catalog/services

# DNS discovery
dig @localhost -p 8600 web.service.consul
Enter fullscreen mode Exit fullscreen mode

Service Mesh (Connect)

service {
  name = "web"
  port = 8080
  connect {
    sidecar_service {
      proxy {
        upstreams {
          destination_name = "api"
          local_bind_port  = 9091
        }
      }
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

Real-World Use Case

A company ran services on both K8s and legacy VMs. K8s DNS only worked within the cluster. Consul: unified service discovery across both. VMs register via agent, K8s services via sync. One DNS namespace for everything.

Quick Start

brew install consul
consul agent -dev
# UI at http://localhost:8500
Enter fullscreen mode Exit fullscreen mode

Resources


Need service monitoring data? Check out my tools on Apify or email spinov001@gmail.com for custom solutions.

Top comments (0)