In this hands-on tutorial, you’ll learn how to manage key/value pairs in HashiCorp Consul’s K/V store using three methods: the web UI, the CLI, and the HTTP API. We’ll cover adding, querying, and deleting entries, plus best practices for decoding API responses.Documentation Index
Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
Use this file to discover all available pages before exploring further.
1. Prerequisites
- SSH access to one of your Consul server nodes
- Consul UI open in your browser (defaults to http://127.0.0.1:8500/ui)
2. Adding Data via the CLI
Use theconsul kv put command to insert entries under the apps/eCommerce prefix.
3. Deleting an Entry
If you need to remove a key, useconsul kv delete. For example, to delete the connection string:
4. Adding Data for the Search Service
Next, create configuration entries for a hypothetical search service:If you don’t see the new entries right away, click the Refresh button in the UI or clear your browser cache.
5. Querying Data in the CLI
Retrieve a value directly from the CLI:6. Querying Data via the HTTP API
Consul’s HTTP API returns values in Base64. First, inspect the raw JSON:Any application using Consul’s K/V HTTP API must Base64-decode the
Value field before use.7. Operation Summary
| Operation | CLI Command | API Endpoint |
|---|---|---|
| Add Key | consul kv put <key> <value> | POST /v1/kv/:key |
| Delete Key | consul kv delete <key> | DELETE /v1/kv/:key |
| Get Key (CLI) | consul kv get <key> | — |
| Get Key (API) | — | GET /v1/kv/:key (Base64-encoded) |