Skip to main content

Overview

ConfigMaps provide a way to inject configuration data into application containers. The exchange platform uses ConfigMaps to manage non-sensitive configuration for all services including database connections, Redis URLs, and service-specific settings.

ConfigMap Manifests

PostgreSQL Database Configuration

The exchange-postgres-config ConfigMap manages PostgreSQL database credentials and settings. Location: postgres-db/config-map.yml
apiVersion: v1
kind: ConfigMap
metadata:
  name: exchange-postgres-config
data:
  POSTGRES_USER: root
  POSTGRES_PASSWORD: root
  POSTGRES_DB: exchange-db
Configuration Keys:
KeyValueDescription
POSTGRES_USERrootPostgreSQL database username
POSTGRES_PASSWORDrootPostgreSQL database password
POSTGRES_DBexchange-dbDatabase name
Used By: exchange-postgres-deployment Reference: postgres-db/deployment.yml:20-35

Engine Service Configuration

The exchange-engine-config ConfigMap provides database and Redis connection strings for the engine service. Location: engine/config-map.yml
apiVersion: v1
kind: ConfigMap
metadata:
  name: exchange-engine-config
data:
  database_url: "postgres://root:[email protected]:80/exchange-db"
  redis_url: "redis://exchange-redis-service.default.svc.cluster.local:80"
Configuration Keys:
KeyValueDescription
database_urlPostgreSQL connection stringFull database URL with credentials and service endpoint
redis_urlRedis connection stringRedis service URL for pub/sub and caching
Used By: exchange-engine-deployment Reference: engine/deployment.yml:18-28

Database Processor Configuration

The exchange-db-processor-config ConfigMap manages configuration for the database processing service. Location: db-processor/config-map.yml
apiVersion: v1
kind: ConfigMap
metadata:
  name: exchange-db-processor-config
data:
  database_url: "postgres://root:[email protected]:80/exchange-db"
  redis_url: "redis://exchange-redis-service.default.svc.cluster.local:80"
Configuration Keys:
KeyValueDescription
database_urlPostgreSQL connection stringDatabase connection for processing operations
redis_urlRedis connection stringRedis for job queues and event handling
Used By: exchange-db-processor-deployment Reference: db-processor/deployment.yml:18-28

WebSocket Service Configuration

The exchange-ws-stream-config ConfigMap configures the WebSocket streaming service. Location: websocket/config-map.yml
apiVersion: v1
kind: ConfigMap
metadata:
  name: exchange-ws-stream-config
data:
  ws_stream_url: "0.0.0.0:4000"
  redis_url: "redis://exchange-redis-service.default.svc.cluster.local:80"
Configuration Keys:
KeyValueDescription
ws_stream_url0.0.0.0:4000WebSocket server bind address and port
redis_urlRedis connection stringRedis for real-time message streaming
Used By: exchange-ws-stream-deployment Reference: websocket/deployment.yml:20-30

Usage Patterns

Referencing ConfigMap Values in Deployments

ConfigMap values are injected into containers as environment variables using configMapKeyRef:
env:
  - name: DATABASE_URL
    valueFrom:
      configMapKeyRef:
        name: exchange-engine-config
        key: database_url
  - name: REDIS_URL
    valueFrom:
      configMapKeyRef:
        name: exchange-engine-config
        key: redis_url

Applying ConfigMaps

Apply ConfigMaps before deploying dependent services:
# Apply individual ConfigMap
kubectl apply -f postgres-db/config-map.yml

# Apply all ConfigMaps
kubectl apply -f postgres-db/config-map.yml \
               -f engine/config-map.yml \
               -f db-processor/config-map.yml \
               -f websocket/config-map.yml

Viewing ConfigMaps

# List all ConfigMaps
kubectl get configmaps

# View specific ConfigMap
kubectl describe configmap exchange-engine-config

# Get ConfigMap data in YAML format
kubectl get configmap exchange-engine-config -o yaml

Updating ConfigMaps

# Edit ConfigMap directly
kubectl edit configmap exchange-engine-config

# Or update from file
kubectl apply -f engine/config-map.yml

# Restart pods to pick up changes
kubectl rollout restart deployment exchange-engine-deployment

Best Practices

Security Considerations

Never store sensitive data like passwords, API keys, or tokens in ConfigMaps. Use Secrets instead. ConfigMaps are stored unencrypted in etcd.
Current Issue: The exchange-postgres-config ConfigMap stores the database password in plain text. For production environments, migrate these credentials to a Secret.

Service Discovery

All services use Kubernetes DNS for service discovery:
<service-name>.<namespace>.svc.cluster.local:<port>
Example: exchange-postgres-service.default.svc.cluster.local:80

Configuration Organization

  • One ConfigMap per service: Each service has its own ConfigMap for isolation
  • Co-located with deployments: ConfigMaps are stored in the same directory as their corresponding deployment files
  • Clear naming convention: All ConfigMaps follow the pattern exchange-<service>-config

Immutability

For production environments, consider making ConfigMaps immutable:
apiVersion: v1
kind: ConfigMap
metadata:
  name: exchange-engine-config
immutable: true
data:
  database_url: "..."
  redis_url: "..."
Benefits:
  • Protects against accidental updates
  • Improves cluster performance by reducing load on kube-apiserver
  • Forces explicit versioning through new ConfigMap creation

Version Control

Always version control your ConfigMap manifests and track changes through Git commits. This provides an audit trail and enables easy rollbacks.

Connection String Patterns

PostgreSQL URLs

Format: postgres://[user]:[password]@[host]:[port]/[database] Example:
postgres://root:[email protected]:80/exchange-db

Redis URLs

Format: redis://[host]:[port] Example:
redis://exchange-redis-service.default.svc.cluster.local:80

Troubleshooting

ConfigMap Not Found

# Check if ConfigMap exists
kubectl get configmap exchange-engine-config

# If not found, apply it
kubectl apply -f engine/config-map.yml

Pod Not Picking Up ConfigMap Changes

ConfigMap updates don’t automatically restart pods:
# Manually restart the deployment
kubectl rollout restart deployment exchange-engine-deployment

# Or delete pods to force recreation
kubectl delete pod -l app=exchange-engine

Verify Environment Variables

Check that ConfigMap values are properly injected:
# Get pod name
kubectl get pods -l app=exchange-engine

# Check environment variables
kubectl exec <pod-name> -- env | grep -E '(DATABASE_URL|REDIS_URL)'

Build docs developers (and LLMs) love