Skip to content

Latest commit

 

History

History
81 lines (64 loc) · 2.5 KB

K8s-Configmap.md

File metadata and controls

81 lines (64 loc) · 2.5 KB

LAB: K8s Configmap

This scenario shows:

  • how to create config map (declerative way),
  • how to use configmap: volume and environment variable,
  • how to create configmap with command (imperative way),
  • how to get/delete configmap

Steps

  • Run minikube (in this scenario, K8s runs on WSL2- Ubuntu 20.04) ("minikube start")

image

apiVersion: v1
kind: ConfigMap
metadata:
  name: myconfigmap               
data:
  db_server: "db.example.com"        # configmap key-value parameters
  database: "mydatabase"
  site.settings: |
    color=blue
    padding:25px
---
apiVersion: v1
kind: Pod
metadata:
  name: configmappod
spec:
  containers:
  - name: configmapcontainer
    image: nginx
    env:                             # configmap using environment variable
      - name: DB_SERVER
        valueFrom:
          configMapKeyRef:           
            name: myconfigmap        # configmap name, from "myconfigmap" 
            key: db_server
      - name: DATABASE
        valueFrom:
          configMapKeyRef:
            name: myconfigmap
            key: database
    volumeMounts:
      - name: config-vol
        mountPath: "/config"
        readOnly: true
  volumes:
    - name: config-vol               # transfer configmap parameters using volume
      configMap:
        name: myconfigmap

image

  • Create configmap and the pod:

image

  • Run bash in the pod:

image

kubectl create configmap myconfigmap2 --from-literal=background=red --from-file=theme.txt

image

  • Delete configmap:

image