Skip to content

Latest commit

 

History

History
77 lines (61 loc) · 2.21 KB

K8s-Configmap.md

File metadata and controls

77 lines (61 loc) · 2.21 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

  • Create Yaml file (config.yaml) in your directory and copy the below definition into the file:
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
  • Create configmap and the pod:

image

  • Run bash in the pod:

image

  • Define configmap with imperative way (--from-file and --from-literal) (create a file and put into "theme=dark")
kubectl create configmap myconfigmap2 --from-literal=background=red --from-file=theme.txt

image

  • Delete configmap:

image