Skip to content

Latest commit

 

History

History
89 lines (78 loc) · 2.36 KB

08-Configure-ConfigMaps-in-Applications.md

File metadata and controls

89 lines (78 loc) · 2.36 KB

Configure ConfigMaps in Applications

In this section, we will take a look at configuring configmaps in applications

ConfigMaps

  • There are 2 phases involved in configuring ConfigMaps.
    • First, create the configMaps
    • Second, Inject then into the pod.
  • There are 2 ways of creating a configmap.
    • The Imperative way

      $ kubectl create configmap app-config --from-literal=APP_COLOR=blue --from-literal=APP_MODE=prod
      $ kubectl create configmap app-config --from-file=app_config.properties (Another way)
      

      cmi

    • The Declarative way

      apiVersion: v1
      kind: ConfigMap
      metadata:
       name: app-config
      data:
       APP_COLOR: blue
       APP_MODE: prod
      
      Create a config map definition file and run the 'kubectl create` command to deploy it.
      $ kubectl create -f config-map.yaml
      

      cmd1

View ConfigMaps

  • To view configMaps

    $ kubectl get configmaps (or)
    $ kubectl get cm
    
  • To describe configmaps

    $ kubectl describe configmaps
    

    cmv

ConfigMap in Pods

  • Inject configmap in pod

    apiVersion: v1
    kind: Pod
    metadata:
      name: simple-webapp-color
    spec:
     containers:
     - name: simple-webapp-color
       image: simple-webapp-color
       ports:
       - containerPort: 8080
       envFrom:
       - configMapRef:
           name: app-config
    
    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: app-config
    data:
      APP_COLOR: blue
      APP_MODE: prod
    
    $ kubectl create -f pod-definition.yaml
    

    cmp

There are other ways to inject configuration variables into pod

  • You can inject it as a Single Environment Variable

  • You can inject it as a file in a Volume

    cmp1

K8s Reference Docs