☸️Config Map

Describe about What is Config map?

When we would like to add the env variable to Pod , we can do it by add the property called env in definition file

# Pod Template
apiVersion: v1
kind: Pod
metadata:
  name: nginx
spec:
  containers:
  - name: nginx
    image: nginx:1.14.2
    ports:
    - containerPort: 80
    env:
      - name:
        value:   
      - name:
        value:
    # For ConfigMap case (1)
      - name: APP_COLOR
        valueFrom: 
          configMapRef:
            name: app-config
            key: APP_COLOR  
    # For ConfigMap case (2)
    envFrom:
      - configMapRef:
          name:
    # For ConfigMap case (3)
    volumes:
    - name: app-config-volume
      configMap:
        name: app-config               

but It's hard to manage in the configuration in definition file so we have Config map for managing the configuration

CheatSheet

  1. Create Configmap (Imperative way):

  • kubectl create configmap <config_name> --from-literal=<key>=<value>

  • kubectl create configmap <config_name> --from-file=<path_to_file>

  1. Create Configmap (Declarative way):

# Configmap Template
apiVersion: v1
kind: ConfigMap
metadata:
  name: <configmap_name>
data:
  <key>: <value>

Last updated