---
# ConfigMap for application configuration
# Use for non-sensitive configuration data
apiVersion: v1
kind: ConfigMap
metadata:
  name: web-app-config
  namespace: default
  labels:
    app.kubernetes.io/name: web-app
    app.kubernetes.io/component: configuration
  annotations:
    description: "Application configuration settings"
data:
  # Simple key-value pairs
  app.name: "web-app"
  app.version: "1.0.0"
  log.level: "info"
  config.path: "/etc/app/config"

  # Database configuration (non-sensitive)
  database.host: "postgres.default.svc.cluster.local"
  database.port: "5432"
  database.name: "appdb"
  database.pool.min: "2"
  database.pool.max: "10"

  # Redis configuration
  redis.host: "redis.default.svc.cluster.local"
  redis.port: "6379"
  redis.db: "0"

  # Feature flags
  feature.new-ui: "true"
  feature.analytics: "true"
  feature.beta-features: "false"

  # Configuration file (multi-line)
  app.properties: |
    # Application Properties
    server.port=8080
    server.host=0.0.0.0
    server.timeout=30s

    # Logging
    log.format=json
    log.output=stdout

    # Metrics
    metrics.enabled=true
    metrics.port=9090

  # JSON configuration
  config.json: |
    {
      "server": {
        "port": 8080,
        "host": "0.0.0.0",
        "cors": {
          "enabled": true,
          "origins": ["https://example.com"]
        }
      },
      "database": {
        "pool": {
          "min": 2,
          "max": 10
        }
      }
    }

  # YAML configuration
  config.yaml: |
    server:
      port: 8080
      host: 0.0.0.0
      timeout: 30s

    logging:
      level: info
      format: json

    features:
      new_ui: true
      analytics: true

---
# Example: Using ConfigMap as environment variables
apiVersion: v1
kind: Pod
metadata:
  name: config-env-example
spec:
  securityContext:
    runAsNonRoot: true
    runAsUser: 1000
    fsGroup: 2000
  containers:
  - name: app
    image: nginx:alpine
    securityContext:
      allowPrivilegeEscalation: false
      readOnlyRootFilesystem: true
      capabilities:
        drop:
        - ALL
    # Load all keys as environment variables
    envFrom:
    - configMapRef:
        name: web-app-config
    # Or load specific keys
    env:
    - name: DATABASE_HOST
      valueFrom:
        configMapKeyRef:
          name: web-app-config
          key: database.host
    resources:
      requests:
        cpu: 50m
        memory: 64Mi
      limits:
        cpu: 100m
        memory: 128Mi

---
# Example: Using ConfigMap as volume mount
apiVersion: v1
kind: Pod
metadata:
  name: config-volume-example
spec:
  securityContext:
    runAsNonRoot: true
    runAsUser: 1000
    fsGroup: 2000
  containers:
  - name: app
    image: nginx:alpine
    securityContext:
      allowPrivilegeEscalation: false
      readOnlyRootFilesystem: true
      capabilities:
        drop:
        - ALL
    volumeMounts:
    # Mount entire ConfigMap
    - name: config-volume
      mountPath: /etc/config
      readOnly: true
    # Mount specific keys
    - name: app-properties
      mountPath: /etc/app/application.properties
      subPath: app.properties
      readOnly: true
    resources:
      requests:
        cpu: 50m
        memory: 64Mi
      limits:
        cpu: 100m
        memory: 128Mi
  volumes:
  - name: config-volume
    configMap:
      name: web-app-config
      defaultMode: 0444  # Read-only
  - name: app-properties
    configMap:
      name: web-app-config
      items:
      - key: app.properties
        path: app.properties
        mode: 0444
