Clean • Professional
Managing data and configuration is a critical part of running applications in Kubernetes. Since containers are temporary by nature, real-world applications require persistent storage and flexible configuration management to work reliably.
👉 In simple words: Kubernetes provides built-in solutions to store data safely and manage application settings efficiently.
In Kubernetes, pods can be created, restarted, or deleted at any time. Without proper storage and configuration management, this can lead to serious issues.
Common challenges without proper setup:
A Volume in Kubernetes is used to store data inside a pod. It allows containers to persist and share data during the pod’s lifecycle.
Unlike containers:
Example
apiVersion: v1
kind: Pod
metadata:
name: volume-pod
spec:
containers:
- name: app
image: nginx
volumeMounts:
- mountPath: /data
name: my-volume
volumes:
- name: my-volume
emptyDir: {}
What This Configuration Does
/dataemptyDir, which provides temporary storage👉 Any data written to /data will remain available while the pod is running, but it will be deleted when the pod is removed.
A Persistent Volume (PV) is a storage resource in a Kubernetes cluster that provides long-term storage independent of pods.
Unlike normal pod storage, a PV exists at the cluster level, not inside a pod. This means data stored in a PV will not be deleted even if pods are removed or restarted.
Key Features of PV
👉 In simple words: PV is a permanent storage space inside Kubernetes that keeps your data safe.
Example of Persistent Volume (PV)
apiVersion: v1
kind: PersistentVolume
metadata:
name: my-pv
spec:
capacity:
storage: 5Gi
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
hostPath:
path: /mnt/data
A Persistent Volume Claim (PVC) is a request made by a pod for storage in a Kubernetes cluster.
It acts like a storage request ticket that asks Kubernetes to provide a suitable Persistent Volume (PV). Once matched, the PV is attached to the pod so it can store data safely.
Key Features of PVC
👉 In simple words: PVC is how a pod asks Kubernetes for storage.
Example (PVC)
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: my-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
Kubernetes provides powerful tools to manage application configuration separately from application code. This makes applications more flexible, scalable, and easier to maintain.
A ConfigMap is used to store non-sensitive configuration data such as environment variables and application settings.
It helps you change configuration without modifying your application code.
Common Use Cases of ConfigMap
Example
apiVersion: v1
kind: ConfigMap
metadata:
name: app-config
data:
APP_MODE: production
LOG_LEVEL: debug
Using ConfigMap Inside a Pod
You can inject ConfigMap values into a pod as environment variables.
env:
- name: APP_MODE
valueFrom:
configMapKeyRef:
name: app-config
key: APP_MODE
Secrets in Kubernetes are used to store sensitive data securely such as passwords, API keys, tokens, and other confidential information.
Unlike ConfigMaps, Secrets are designed to handle critical data that should not be exposed in plain text.
Common Use Cases of Secrets
Example
apiVersion: v1
kind: Secret
metadata:
name: app-secret
type: Opaque
data:
DB_PASSWORD: cGFzc3dvcmQ=
| Feature | ConfigMap | Secret |
|---|---|---|
| Data Type | Non-sensitive data | Sensitive data |
| Purpose | Store application configuration | Store confidential information |
| Storage Format | Plain text (readable format) | Base64 encoded format |
| Security Level | Low security | Higher security (but still needs extra protection) |
| Common Use Case | App settings, environment variables | Passwords, API keys, tokens |
| Visibility | Easily readable inside cluster | Hidden but can be decoded |
In a production Kubernetes system:
This ensures:
Kubernetes Storage & Configuration provides a complete solution for managing both data persistence and application settings in a scalable way.
Together, they make Kubernetes applications secure, scalable, and production-ready