Skip to content

Environment Management

NthLayer supports multi-environment deployments with environment-specific configurations.

Overview

Environments allow you to customize service configurations for different deployment targets (dev, staging, production) while keeping a single source of truth in your service.yaml.

Commands

list-environments

Discover available environment configurations.

# List environments in current directory
nthlayer list-environments

# List environments for a specific service
nthlayer list-environments --service services/payment-api.yaml

# Search a specific directory
nthlayer list-environments --directory ./config

Example output:

NthLayer: List Environments

Directory: /home/user/project

βœ“ Found 3 environment(s):

πŸ“¦ development
   Shared: development.yaml

πŸ“¦ staging
   Shared: staging.yaml
   Service-specific: 2 file(s)
      β€’ payment-api: payment-api-staging.yaml
      β€’ user-service: user-service-staging.yaml

πŸ“¦ production
   Shared: production.yaml
   Service-specific: 1 file(s)
      β€’ payment-api: payment-api-production.yaml

Usage:
   nthlayer generate-slo service.yaml --env development
   nthlayer validate service.yaml --env development

diff-envs

Compare configurations between two environments to see what changes between them.

nthlayer diff-envs services/payment-api.yaml staging production

Example output:

NthLayer: Environment Diff

Service: payment-api
Comparing: staging β†’ production

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Field           β”‚ staging     β”‚ production  β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ replicas        β”‚ 2           β”‚ 5           β”‚
β”‚ resources.cpu   β”‚ 500m        β”‚ 2000m       β”‚
β”‚ resources.memoryβ”‚ 512Mi       β”‚ 2Gi         β”‚
β”‚ slo.availabilityβ”‚ 99.5%       β”‚ 99.95%      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

3 differences found

Options:

Option Description
--show-all Show all fields, not just differences

validate-env

Validate an environment configuration for correctness.

# Basic validation
nthlayer validate-env production

# Validate against a specific service
nthlayer validate-env production --service services/payment-api.yaml

# Strict mode (warnings become errors)
nthlayer validate-env production --strict

What gets validated:

  • Environment file syntax (valid YAML)
  • Required fields present
  • Value types match expected schema
  • Variable references resolve correctly
  • No conflicts with service defaults

Example output:

NthLayer: Validate Environment

Environment: production
Directory: ./environments

βœ“ Found environment file: production.yaml

Validating...
  βœ“ Valid YAML syntax
  βœ“ Required fields present
  βœ“ Value types correct
  ⚠ Warning: 'debug_mode' is set to true in production

Validation passed with 1 warning(s)

Environment File Structure

Shared Environment File

environments/production.yaml:

environment: production

# Override service defaults
defaults:
  replicas: 3
  resources:
    cpu: "1000m"
    memory: "1Gi"

# Environment-specific SLO targets
slo:
  availability: 99.95
  latency_p99_ms: 200

# Prometheus endpoint for this environment
prometheus:
  url: https://prometheus.prod.example.com

# Grafana for this environment
grafana:
  url: https://grafana.prod.example.com
  folder: Production

Service-Specific Environment File

environments/payment-api-production.yaml:

environment: production
service: payment-api

# Service-specific overrides for production
replicas: 5
resources:
  cpu: "2000m"
  memory: "2Gi"

# Stricter SLO for payment service
slo:
  availability: 99.99
  latency_p99_ms: 100

Using Environments

With Generate Commands

# Generate with environment-specific config
nthlayer apply services/payment-api.yaml --env production

# Preview what would be generated
nthlayer plan services/payment-api.yaml --env production

With Validation Commands

# Verify metrics exist in production Prometheus
nthlayer verify services/payment-api.yaml --env production

# Check deployment gate against production SLOs
nthlayer check-deploy services/payment-api.yaml --env production

With SLO Commands

# Collect SLO metrics from production
nthlayer slo collect services/payment-api.yaml --env production

Best Practices

1. Use Shared Defaults

Put common configuration in shared environment files, override only what's different per-service.

2. Validate Before Deploy

# In CI/CD pipeline
nthlayer validate-env $ENVIRONMENT --strict
nthlayer validate services/*.yaml --env $ENVIRONMENT

3. Compare Before Promotion

# Before promoting staging to production
nthlayer diff-envs services/payment-api.yaml staging production

4. Keep Environments Consistent

Use the same environment names across all services for predictable behavior.

Directory Structure

Recommended layout:

project/
β”œβ”€β”€ services/
β”‚   β”œβ”€β”€ payment-api.yaml
β”‚   β”œβ”€β”€ user-service.yaml
β”‚   └── notification-worker.yaml
β”œβ”€β”€ environments/
β”‚   β”œβ”€β”€ development.yaml           # Shared dev config
β”‚   β”œβ”€β”€ staging.yaml               # Shared staging config
β”‚   β”œβ”€β”€ production.yaml            # Shared production config
β”‚   β”œβ”€β”€ payment-api-production.yaml    # Service-specific override
β”‚   └── user-service-staging.yaml      # Service-specific override
└── generated/
    β”œβ”€β”€ development/
    β”œβ”€β”€ staging/
    └── production/