From fe2232fdcb763eaad7546d6a6aeb5851a9670d87 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 9 Jul 2025 12:37:15 +0330 Subject: [PATCH] kuber doc: configmap --- .../Kubernetes/Commands/3-Commands.md | 4 + .../Kubernetes/Commands/config-map.md | 104 ++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 Containerization & Orchestration/Kubernetes/Commands/config-map.md diff --git a/Containerization & Orchestration/Kubernetes/Commands/3-Commands.md b/Containerization & Orchestration/Kubernetes/Commands/3-Commands.md index 02f0118..efab6b8 100755 --- a/Containerization & Orchestration/Kubernetes/Commands/3-Commands.md +++ b/Containerization & Orchestration/Kubernetes/Commands/3-Commands.md @@ -115,3 +115,7 @@ This guide provides a concise reference for common `kubectl` commands used to ma Any YAML files placed in `/etc/kubernetes/manifests/` are automatically loaded when the kubelet starts (for example, after a server reboot). + +```bash +kubectl cp -n :dir/ ./ +``` diff --git a/Containerization & Orchestration/Kubernetes/Commands/config-map.md b/Containerization & Orchestration/Kubernetes/Commands/config-map.md new file mode 100644 index 0000000..778a5c7 --- /dev/null +++ b/Containerization & Orchestration/Kubernetes/Commands/config-map.md @@ -0,0 +1,104 @@ +# ๐Ÿงพ 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 +``` +