Catalog / Consul Cheatsheet
Consul Cheatsheet
A quick reference for Consul, covering key concepts, CLI commands, configuration, and best practices for service discovery, health checking, and configuration management.
Core Concepts
Service Discovery
Service Discovery enables applications to find and connect to each other dynamically. Consul maintains a catalog of available services and their locations. |
Key Features:
|
Benefits:
|
Health Checking
Health Checks ensure that only healthy services are used. Consul supports various health check types. |
Types of Health Checks:
|
Health Check States:
|
Key/Value Store
Key/Value (KV) Store provides a hierarchical storage system for configuration data and other metadata. It is commonly used for centralized configuration management. |
Key Features:
|
Use Cases:
|
CLI Commands
Basic Commands
|
Lists the members of the Consul cluster. |
|
Displays information about the Consul agent. |
|
Lists all registered services. |
|
Lists all registered nodes. |
KV Store Commands
|
Sets a key/value pair in the KV store. Example:
|
|
Retrieves the value for a given key. Example:
|
|
Deletes a key from the KV store. Example:
|
|
Exports keys with specified prefix. Example:
|
Agent Commands
|
Starts a Consul agent in development mode (not for production). |
|
Starts a Consul server agent. (example) |
|
Starts a Consul client agent and joins an existing cluster. (example) |
Configuration
Agent Configuration
Consul agent configuration is typically done via JSON files. Key parameters include |
Example configuration file (
|
Start the agent with the configuration file:
|
Service Definitions
Services are defined in JSON files and placed in the Consul configuration directory or registered via the HTTP API. |
Example service definition (
|
Place the |
Health Check Definitions
Health checks can be defined alongside service definitions or separately. |
Example health check definition (
|
Place the |
API Endpoints
Service Catalog
|
Lists all services in the catalog. Example:
|
|
Lists instances of a specific service. Example:
|
|
Lists healthy instances of a specific service. Example:
|
Key/Value Store
|
Retrieves the value for a given key. Example:
|
|
Sets a key/value pair. Example:
|
|
Deletes a key. Example:
|
Agent API
|
Registers a service. Example:
|
|
Deregisters a service. Example:
|
|
Registers a check. Example:
|