Shashikant shah

Saturday, 15 February 2025

Storage Volumes in Kubernetes.

 

1.Storage Volumes  in Kubernetes.

In Kubernetes, a storage volume is a way to provide persistent storage for containers. By default, containers have ephemeral storage, meaning data is lost when the container is terminated. Volumes allow containers to store data persistently, even if they are restarted or rescheduled to different nodes. 

Volumes are mounted into containers and can hold data throughout the lifecycle of the pod.




Ephemeral (Stateless):- If the pod delete then data will also deleted.

a)     emptyDir

b)     hostPath

c)      ConfigMap

d)     Secret

Durable:- (Stateful) If the pod will be deleted but the data will not be deleted. data will remain constant in volume

a)     PersistentVolume (PV)

b)     NFS

c)      iSCSI

d)     CephFS

e)     GlusterFS

f)       AWS EBS

g)     GCE PD

h)     Azure Disk

i)       Azure File

j)       CSI

k)     local

2. 2. Different types of volume support clusters are:-




emptyDir :-

emptyDir is an ephemeral volume in Kubernetes that provides temporary storage for a pod. If the pods are deleted the data is lost.

a). Single -Container Pod with emptyDir.














1.     The data in emptyDir Volumes is not lost when pods are restarted, but if the data is outside of emptyDir  Volumes then it will be lost.

2.     Data is lost if the pod is deleted or moved to a different node.

3.     Two containers within the same pod to share an emptyDir Volumes.

4.     If there are two different pods then data will not be shared


b). Multi-Container in the same Pod with emptyDir.













Access the first container (busybox1):





Check from the second container (busybox2):





hostPath :

A hostPath volume mounts a file or directory from the host node into a pod. This is useful for persistent storage on a single-node cluster but not recommended for multi-node clusters node.

If PV creates and mounts with hostPath 


apiVersion: v1

kind: Pod

metadata:

  name: example-hostpath-pod

spec:

  containers:

    - name: example-container

      image: busybox

      command: ["sleep", "3600"]

      volumeMounts:

        - mountPath: /data

          name: my-hostpath-volume

  volumes:

    - name: my-hostpath-volume

      hostPath:

        path: /mnt/data  # Path on the node

        type: DirectoryOrCreate  # Creates the directory if it doesn't exist




No comments:

Post a Comment