Prerequisites
- A running Consul cluster with KV entries under
apps/ecommerce - SSH access to your application server
- (Optional) Consul ACL token if your cluster enforces ACLs
Example KV Entries
| Consul KV Path | Value |
|---|---|
apps/ecommerce/database_host | "customer-db" |
apps/ecommerce/database | "billing" |
apps/ecommerce/connection_string | "Server=customer-db;Database=billing;User Id=..." |
1. Install envconsul
Download the latest Linux AMD64 binary from HashiCorp’s release archive:PATH:
Make sure to update the version number in the URL if a newer release is available.
2. Fetch and Export KV Data
Useenvconsul to pull all keys under the apps/ecommerce prefix and convert them to uppercase environment variables:
Common Flags
| Flag | Description |
|---|---|
-prefix | Consul KV path to fetch |
-uppercase | Convert all keys to uppercase environment variable |
-- | Separator before the command to execute |
3. Launch Your Application with envconsul
To ensure your application picks up the variables at startup and on any KV change:If your app requires a Consul ACL token, set
CONSUL_HTTP_TOKEN in the environment or pass -token to envconsul.Summary
In this demo, you:- Installed
envconsulon a Linux server. - Retrieved KV pairs from Consul and exposed them as environment variables.
- Launched your application to inherit and watch for configuration updates automatically.
envconsul, your service maintains up-to-date settings without manual polling or restarts.