# ๐Ÿงพ Kubernetes ConfigMap ## ๐Ÿ“˜ What is a ConfigMap? A **ConfigMap** allows you to **store configuration data** in key-value pairs that can be: * Mounted as files in a Pod * Exposed as environment variables * Consumed by Kubernetes workloads without hardcoding settings in container images --- ## โš™๏ธ Creating a ConfigMap from Files Create a ConfigMap from one or more files: ```bash kubectl -n create configmap --from-file= ``` ### โœ… Examples ```bash # Create from a single file kubectl -n create configmap nginx-conf --from-file=./nginx.conf # Create from multiple files kubectl -n create configmap nginx-conf --from-file=./nginx.conf --from-file=./site.conf ``` --- ## ๐Ÿ“‚ Viewing and Editing ConfigMaps ```bash # List ConfigMaps in a namespace kubectl get cm -n # Edit a ConfigMap kubectl -n edit configmap ``` --- ## ๐Ÿ“„ ConfigMap YAML Example ```yaml apiVersion: v1 kind: ConfigMap metadata: name: game-demo data: # Key-value style player_initial_lives: "3" ui_properties_file_name: "user-interface.properties" # Multi-line file-style entries game.properties: | enemy.types=aliens,monsters player.maximum-lives=5 user-interface.properties: | color.good=purple color.bad=yellow allow.textmode=true ``` --- ## ๐Ÿš€ Deployment Example: Using ConfigMap as Volume ```yaml apiVersion: apps/v1 kind: Deployment metadata: name: app-1 namespace: dev labels: app.kubernetes.io/name: nginx spec: replicas: 3 selector: matchLabels: app.kubernetes.io/name: nginx template: metadata: labels: app.kubernetes.io/name: nginx os: linux spec: containers: - name: nginx image: nginx ports: - containerPort: 80 volumeMounts: - name: configfile mountPath: /etc/nginx/nginx.conf subPath: nginx.conf # Mount specific file from ConfigMap volumes: - name: configfile configMap: name: nginx-conf ```