Back to articles
Consul Has a Free API: Here's How to Use It for Service Discovery Automation
How-ToDevOps

Consul Has a Free API: Here's How to Use It for Service Discovery Automation

via Dev.to DevOpsAlex Spinov

HashiCorp Consul provides a powerful HTTP API for service discovery, health checking, key-value storage, and network configuration. It's the backbone of service mesh architectures and it's completely free. Why Use the Consul API? Discover services dynamically without hardcoded IPs Health check all services automatically Store configuration in a distributed key-value store Automate DNS and load balancing for microservices Getting Started # Start Consul agent consul agent -dev # Register a service curl -X PUT http://localhost:8500/v1/agent/service/register -d '{ "Name": "web-api", "Port": 8080, "Tags": ["v2", "production"], "Check": { "HTTP": "http://localhost:8080/health", "Interval": "10s" } }' # Discover services curl -s http://localhost:8500/v1/catalog/services | jq . # Get service instances curl -s http://localhost:8500/v1/health/service/web-api?passing = true | jq '.[] | {node: .Node.Node, address: .Service.Address, port: .Service.Port}' Python Client import requests class ConsulCl

Continue reading on Dev.to DevOps

Opens in a new tab

Read Full Article
6 views

Related Articles