Skip to main content

Configuration Management

This example builds on Ingress Configuration by adding configuration through environment variables.

What You'll Learn

In this lesson, you'll learn:

  • How to inject configuration as environment variables
  • Config vs Secrets (when to use each)
  • Per-environment configuration with Kustomize
  • Best practices for configuration management

What Gets Created

In addition to resources from Ingress Configuration, the platform updates the Deployment to include environment variables.

What Changed

Added the spec.config section:

apiVersion: meta.p6m.dev/v1alpha1
kind: PlatformApplication
metadata:
name: demo-http-echo
namespace: demo-http-echo
labels:
p6m.dev/app: demo-http-echo
spec:
# NEW
config:
LOG_LEVEL: debug
HTTP_PORT: "8080"
ENVIRONMENT: dev
APP_NAME: demo-http-echo
# NEW
deployment:
image: mendhak/http-https-echo:31
ports:
- port: 8080
protocol: http
readinessProbe:
port: 8080
path: /
networking:
ingress:
enabled: true
path: /
gateway: public-open

Deploy Steps

ArgoCD automatically updates to your PlatformApplication after the Platform Dispatch Action to update your .platform repository is run.

Let's use the Kinds filter to locate our Pods (spec.containers[0].env) and Deployments (spec.template.spec.containers[0].env), from there we can check the fields to verify our config was applied.

ArgoCD view of deployment with spec.template.spec.containers[0].env highlightedArgoCD view of deployment with spec.template.spec.containers[0].env highlighted

How Config Works

The spec.config section is a simple key-value map:

  • Keys become environment variable names
  • Values become environment variable values (must be strings)
    • Non-string values (numbers, booleans, etc.) must be wrapped in quotes

The platform automatically:

  1. Updates the Deployment specification with your config as environment variables
  2. The Deployment creates a new ReplicaSet to track the updated configuration
  3. Updated Pods replace the old Pods, which are cleaned up automatically

Config vs Secrets

AspectConfig (spec.config)Secrets (spec.secrets)
Use forNon-sensitive settingsAPI keys, passwords, tokens
Stored inGitCloud Secret Store
EncryptedNoYes (at rest)
VisibleYes (in Git, kubectl)No (base64 encoded)
Per-environmentKustomize patchesSeparate secret stores
ExampleDATABASE_HOSTDATABASE_PASSWORD
tip

Want to know more about Best Practices? See Configuration Management - Details for more information.

Next Steps

Troubleshooting

For common issues and solutions, see the Troubleshooting Guide.

Specific sections that may be helpful:

Cleanup

Check out the Cleanup Instructions from the Basic Deployment lesson to remove all resources created in this walkthrough.