update kuber doc: stroage

This commit is contained in:
2025-07-23 14:52:27 +03:30
parent e41aa509c6
commit 26d00e355d
5 changed files with 64 additions and 12 deletions

View File

@@ -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 <namespace> create configmap <configmap-name> --from-file=<file-or-directory>
```
### ✅ Examples
```bash
# Create from a single file
kubectl -n <ns> create configmap nginx-conf --from-file=./nginx.conf
# Create from multiple files
kubectl -n <ns> 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 <namespace>
# Edit a ConfigMap
kubectl -n <namespace> edit configmap <configmap-name>
```
---
## 📄 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
```