Skip to content

Latest commit

 

History

History
68 lines (53 loc) · 1.94 KB

configmap.md

File metadata and controls

68 lines (53 loc) · 1.94 KB

Kubernetes ConfigMap object

A ConfigMap is an API object used to store non-confidential data in key-value pairs. Pods can consume ConfigMaps as environment variables, command-line arguments, or as configuration files in a volume. It allows you to decouple environment-specific configuration from your container images, so that your applications are easily portable.

Reference: Kubernetes Documentation/Concepts/Configuration/ConfigMaps

Command line examples

# get all configmaps in current namespace
k get cm

# create a configmap
k create cm webapp-config-map --from-literal=APP_COLOR=darkblue

Manifest examples

  • Example of a ConfigMap that has some keys with single values, and other keys where the value looks like a fragment of a configuration format:
apiVersion: v1
kind: ConfigMap
metadata:
  name: game-demo
data:
  # property-like keys; each key maps to a simple value
  player_initial_lives: "3"
  ui_properties_file_name: "user-interface.properties"

  # file-like keys
  game.properties: |
    enemy.types=aliens,monsters
    player.maximum-lives=5
  user-interface.properties: |
    color.good=purple
    color.bad=yellow
    allow.textmode=true

Usecases

Configure Pods and Containers

apiVersion: v1
kind: Pod
metadata:
  name: dapi-test-pod
spec:
  containers:
    - name: test-container
      image: k8s.gcr.io/busybox
      command: [ "/bin/sh", "-c", "env" ]
      env:
        - name: SPECIAL_LEVEL_KEY
          valueFrom:
            configMapKeyRef:
              name: special-config
              key: special.how
  restartPolicy: Never

Going further