HashiCorp Consul
Service networking for any runtime, any cloud. Consul provides service discovery, health checking, distributed key-value configuration, and a zero-trust service mesh with automatic mTLS across VMs, containers, and Kubernetes.
Docker Quickstart
# Start a Consul dev agent (in-memory, single node) docker run -d \ --name consul \ -p 8500:8500 \ -p 8600:8600/udp \ hashicorp/consul:latest \ consul agent -dev -client=0.0.0.0 # Access the web UI at http://localhost:8500 # Install the Consul CLI (macOS) brew install consul # Point CLI at local agent export CONSUL_HTTP_ADDR=http://localhost:8500 # Check cluster members consul members # Verify health consul operator autopilot get-config
Service Registration and Health Checks
# Register a service via config file (drop in /etc/consul.d/)
# /etc/consul.d/web.json
{
"service": {
"name": "web",
"id": "web-1",
"tags": ["production", "v2"],
"address": "10.0.0.10",
"port": 8080,
"check": {
"id": "web-health",
"name": "HTTP health check",
"http": "http://localhost:8080/health",
"method": "GET",
"interval": "10s",
"timeout": "3s"
}
}
}
# Register via HTTP API
curl -X PUT http://localhost:8500/v1/agent/service/register \
-H 'Content-Type: application/json' \
-d '{
"Name": "api",
"Port": 3000,
"Check": {
"TCP": "localhost:3000",
"Interval": "10s"
}
}'
# Query registered services
consul catalog services
# Check service health
consul health service web --passing DNS Interface for Service Discovery
# Consul provides a DNS interface at port 8600 # Services are resolvable as: service-name.service.consul # Resolve healthy instances of the 'web' service dig @127.0.0.1 -p 8600 web.service.consul # Resolve with specific tag (only production instances) dig @127.0.0.1 -p 8600 production.web.service.consul # Resolve SRV record (includes port information) dig @127.0.0.1 -p 8600 web.service.consul SRV # Configure system DNS to use Consul (Linux with systemd-resolved) cat > /etc/systemd/resolved.conf.d/consul.conf <<EOF [Resolve] DNS=127.0.0.1:8600 Domains=~consul EOF systemctl restart systemd-resolved # Now applications can just use: http://web.service.consul:8080
Key-Value Store for Configuration
# Write configuration values
consul kv put config/my-app/db_host "postgres.service.consul"
consul kv put config/my-app/max_connections "50"
consul kv put config/my-app/feature_flags '{"dark_mode": true, "beta": false}'
# Read a value
consul kv get config/my-app/db_host
# List all keys under a prefix
consul kv get --recurse config/my-app/
# Watch for changes (blocks until key changes, then prints new value)
consul watch -type=key -key=config/my-app/db_host cat
# Delete a key
consul kv delete config/my-app/old_setting
# Application integration (Go example):
# client, _ := api.NewClient(api.DefaultConfig())
# kv := client.KV()
# pair, _, _ := kv.Get("config/my-app/db_host", nil)
# fmt.Println(string(pair.Value)) Consul Connect: mTLS Service Mesh
# Enable Connect in Consul config
{
"connect": {
"enabled": true
}
}
# Register a service with Connect sidecar proxy
{
"service": {
"name": "api",
"port": 8080,
"connect": {
"sidecar_service": {
"proxy": {
"upstreams": [
{
"destination_name": "database",
"local_bind_port": 5432
}
]
}
}
}
}
}
# Create an Intention: allow api → database
consul intention create api database
# Block all traffic except explicitly allowed pairs
consul intention create -deny "*" "*"
consul intention create api database # allow
consul intention create frontend api # allow
# Traffic flow with Connect:
# frontend:app → frontend:sidecar(mTLS) → api:sidecar(mTLS) → api:app
# All traffic encrypted, all connections authorized by intentions Consul vs Kubernetes DNS vs Istio
| Feature | Consul | Kubernetes DNS (kube-dns) | Istio |
|---|---|---|---|
| Multi-platform | Yes (VMs + containers) | Kubernetes only | Kubernetes only |
| Service mesh / mTLS | Yes (Connect) | No | Yes (advanced) |
| Traffic management | Basic (intentions) | None | Advanced (canary, retries) |
| KV store | Yes | No | No |
| Complexity | Medium | Low | High |
| Best for | Multi-cloud, hybrid, HashiCorp stack | Simple K8s service discovery | Advanced K8s traffic management |
Frequently Asked Questions
What is Consul and what are its main use cases?▼
HashiCorp Consul is a distributed service networking solution with three core capabilities: service discovery (finding where services are running), health checking (automatically routing traffic away from unhealthy instances), and key-value store (distributed configuration). With Consul Connect, it also provides a service mesh with automatic mTLS between services. Use cases include: microservices communicating across dynamic IP addresses, automatic failover when a service crashes, distributed configuration management, and zero-trust networking between services with encrypted mTLS connections.
How does Consul service discovery differ from Kubernetes native DNS?▼
Kubernetes kube-dns provides basic DNS-based service discovery within a single cluster using service names like my-service.namespace.svc.cluster.local. Consul extends this to multi-cluster and hybrid environments (VMs + containers), provides health checking at the service level (not just pod level), supports external services not running in Kubernetes, and integrates with non-Kubernetes environments like legacy VMs. For pure Kubernetes-only workloads, kube-dns is simpler. Consul shines in multi-datacenter setups, hybrid cloud, or when you need fine-grained health checks.
What is Consul Connect and how does mTLS work?▼
Consul Connect is the service mesh component of Consul. It automatically provisions TLS certificates for each service and configures sidecar proxies (Envoy by default) to enforce mutual TLS (mTLS) between services. When service A calls service B, both sides authenticate via certificates issued by Consul's built-in CA. Intentions define which services are allowed to communicate — by default, all communication is blocked and you explicitly allow pairs. This implements zero-trust networking: services cannot communicate unless explicitly permitted, and all traffic is encrypted in transit.
How do I register a service in Consul?▼
Services can be registered in three ways: (1) Config file on the Consul agent — drop a JSON or HCL file in the Consul config directory with the service definition. (2) HTTP API — POST to /v1/agent/service/register with the service definition JSON. (3) Kubernetes integration — deploy the Consul Helm chart and annotate pods with consul.hashicorp.com/connect-inject: 'true'; Consul automatically registers the pods as services. The service definition includes name, port, tags, and health checks (HTTP, TCP, script, or TTL-based).
How does the Consul KV store compare to etcd or Redis for configuration?▼
Consul's KV store is designed for distributed configuration — it supports watches (get notified when a key changes), transactions, and replication across datacenters. It is not designed for high-throughput writes or large values (unlike Redis). Compared to etcd, Consul KV is simpler to use (REST API, web UI, CLI) and integrates naturally with Consul's service discovery and health checking. etcd is optimized for Kubernetes metadata storage with stronger consistency guarantees. Use Consul KV for application configuration that changes occasionally, Vault for secrets, and Redis for caching or high-frequency data.
What is the difference between Consul, Istio, and Kubernetes native service mesh?▼
Consul Connect uses Envoy proxies but is simpler to configure and operates across multiple platforms (VMs, containers, bare metal). Istio is Kubernetes-native with more advanced traffic management (canary, circuit breaking, retries, timeouts), richer observability, and more complex configuration. Kubernetes Gateway API provides basic ingress/service networking but is not a full service mesh. Consul wins for multi-platform, hybrid, or HashiCorp stack users. Istio wins for teams needing advanced Kubernetes traffic management. For simple Kubernetes mTLS without a full service mesh, Cilium or Linkerd are lighter alternatives.
Related Products
on GumroadPremium Workflow Pack
Production-grade workflows, architecture guides, and deployment scripts for teams that ship. 10 advanced CI/CD workflows (blue-green, canary, E2E, security), 5 architecture deep-dives, code review checklist, PR process guide, and 5 battle-tested Bash deployment scripts.
Buy on Gumroad →GitHub Actions CI/CD Templates Pack
12 production-ready GitHub Actions workflow templates covering Node.js, Python, Docker, multi-environment deployments, security scanning, and auto-changelog. Copy, paste, ship.
Buy on Gumroad →Developer Productivity Bundle
Stop rebuilding the same setup every project. 51 VSCode snippets, 40 Git aliases, 5 Docker Compose stacks, 5 GitHub Actions workflows, 5 README templates, and a dotfiles kit. Set up a professional dev environment in under an hour.
Buy on Gumroad →You Might Also Need
HashiCorp Consul Service Mesh Guide
Complete HashiCorp Consul guide for service discovery and service mesh. Learn service registration, health checks, mTLS intentions, Envoy sidecar, KV store, and comparison with Istio.
Open free tool →
Nomad Job Spec Builder
Generate HashiCorp Nomad job specification HCL from form inputs. Build service, batch, and system jobs with Docker/exec drivers, resources, and Consul service registration.
Open free tool →
Vault Policy Generator
Generate HashiCorp Vault HCL policies from path and capabilities form. Build least-privilege Vault policies for secrets access control.
Open free tool →
More Free Tools
Related Articles
Microservices Observability with OpenTelemetry 2026: Tracing, Metrics, Logs
Complete guide to implementing observability in microservices using OpenTelemetry in 2026. Distributed tracing, metrics collection, structured logging, and production-ready setup with Jaeger, Prometheus, and Grafana.
Microservices vs Monolith in 2026: When to Choose What
The honest guide to choosing between microservices and monolithic architecture in 2026. Real tradeoffs, migration strategies, service mesh, event-driven patterns, and case studies from Netflix, Uber, and Shopify.
Cilium Service Mesh vs Istio vs Linkerd: Kubernetes Networking 2026
Comprehensive comparison of Cilium, Istio, and Linkerd for Kubernetes service mesh in 2026. eBPF networking, performance benchmarks, mTLS, observability, and when to use each.
Zero Trust Architecture: A Practical Guide for Web Developers 2026
Implement Zero Trust for web applications: mTLS between services, SPIFFE/SPIRE identity, service mesh security (Istio/Linkerd), token-based auth patterns, and BeyondCorp-style network access.
Docker vs Kubernetes: When to Use Each (2025 Guide)
Docker vs Kubernetes 2025: key differences, Docker Compose vs Kubernetes, cost comparison, and a clear decision framework with real-world use cases.
Enjoying this tool? Get more like it.
Weekly developer tool guides, productivity playbooks & AI tricks. Free. No spam.
Unlock AI-Powered Dev Tools
- ⚡ AI Code Review, Doc Generator & SQL Builder
- ⚡ All premium templates & early access
- ⚡ Member discounts on Gumroad products
$9/mo after trial · Cancel anytime
Want the full toolkit?
Get DevPlaybook Pro
Every template, guide, boilerplate, and automation script in one bundle. 13 premium products — grab them all at once and save big.
MIT licensed · Instant download · No subscription
See what's included → Browse all deals →