Environment Settings
Environment settings allow you to maintain different configurations for development, staging, and production environments using the same template files.Settings Directory Structure
Environment-specific variables are stored in separate directories:env.json file containing environment-specific values.
Development Environment
The development environment uses local service names suitable for Docker Compose or local development.settings/dev/env.json
Key Features
- Local hosts: Service names (e.g.,
http://member) resolve via Docker Compose - Port: Standard port 8080 for local development
- Keycloak: Local Keycloak instance for authentication
- Name: Environment identifier “DEV”
Production Environment
The production environment uses fully qualified domain names (FQDNs) for production services.settings/prod/env.json
Key Features
- Production hosts: Full domain names (e.g.,
http://member.production-host.com) - Port: Same port 8080 (typically behind a load balancer)
- Keycloak: Production Keycloak instance
- Name: Environment identifier “PROD”
Environment Variables Structure
Theenv.json file typically contains:
Common Variables
| Variable | Type | Description |
|---|---|---|
port | number | KrakenD listening port |
name | string | Environment name (DEV, STAGING, PROD) |
security | string | JWT validation endpoint URL |
Service Hosts
Define backend service URLs:Using in Templates
Access variables in your template files:Switching Environments
There are several ways to switch between environments:Method 1: Environment Variable
Set theFC_SETTINGS environment variable to specify which settings directory to use:
Method 2: Inline Environment Variable
Specify the environment when starting KrakenD:Method 3: Docker Compose
In yourdocker-compose.yml:
Method 4: CI/CD Pipeline
In your deployment pipeline:Adding New Environments
To add a staging environment:-
Create the settings directory:
-
Create
env.jsonwith staging-specific values: -
Use it:
Environment-Specific Configuration
Timeouts
Adjust timeouts based on environment:Feature Flags
Enable/disable features per environment:Logging Levels
Best Practices
1. Never Commit Secrets
Don’t store secrets inenv.json files committed to version control. Use:
- Environment variables for secrets
- Secret management tools (Vault, AWS Secrets Manager)
.gitignorefor local environment files
2. Validate Environment Files
Ensure all required variables are present in each environment:3. Document Required Variables
Maintain a README or schema documenting required variables:4. Use Descriptive Names
Use clear, descriptive variable names:5. Keep Parity Between Environments
All environment files should have the same structure:Testing Configuration
Compile and Check
Before deploying, compile and validate your configuration:Compare Environments
Generate and compare configurations:Next Steps
- Learn about flexible configuration templates
- View endpoint configuration examples
- Explore the main configuration file structure