Kubernetes Persistence Volume
This article is part 2 of https://amulyareddyk97.medium.com/advanced-kubernetes-with-doks-d5fdd829eed4. Please go through the link.
- Volumes and Claims
- Life cycle of volumes and claims
- Provisioning types
- Binding and Mounting volume
# Containers are not persistent
# PV is accessible at cluster level, independent of pods
# PVs life cycle is not tied to container lifecycle# Types = Static PV and Dynamic PV
kubectl create -f static-pv.yml
kubectl get pv
kubectl get pv <name>
Life cycle of PV and PVC
# PV is at cluster level
# When developer claims PVC is created at container level
# Though the dev requested for 3GB volume, if the access mode matches, bigger volume is allocated. 10GB here# PVC
kubectl create -f static-pvc.yml
kubectl get pvc # state goes from available to bound state
kubectl get pvc <name>
How to make PV visible inside a container
# Mount PVC to a mount path of a pod
kubectl create -f static-pv-pod.yml
Volume Binding — Phases
Delete # If pod is deleted PV gets deleted
Retain # Even if PVC & pods are deleted, PV remains. We need to # delete PV manually
CSI (Container Storage Interface)
# Without CSI, different volume plugins has to be used to interact with different storages
# CSI is single interface for different external storage systems
# Supports secure 3rd party storages without being shipped with Kubernetes code
# They communicate over gRPC
In CSI, lets create Dynamic PV
kubectl create -f csi-pvc.yml
kubectl get pvc # gets created
kubectl get pv # gets created automatically
kubectl get pod
kubectl describe pod <name> # can see the volume
- Expanding of Volume — change the size
- Cloning of Volume
Static: Delete Pod (removes mounting) -> Delete PVC (removes binding)-> Delete PV
Dynamic: Does automatically. Deleting PVC deleted PV.
Create snapshot out of PVC
# Check if the PVC exists
kubectl get volumesnapshot
Creating new PVC out of snapshot
kubectl get pvc # They have same state, same config
Clone PVC — not snapshot (pvc to pvc)
# Stateful applications store data in StatefulSets (db data, kv pairs) for servers, clients to use# Creates in order -> 0,1,2...
# Once 0 is completely up, 1 starts and so on..
kubectl scale sts <pod_name> replica=5
kubectl get sts
ReplicaSet is the opposite of StatefulSet. It is good for stateless applications.
ReplicaSet, StatefulSet, DeamonSet and Job/CronJobs are workloads.
DeamonSet — defines Pods that provide node-local facilities.
Other Useful commands
kubectl get pod -w
kubectl describe pod <name>
kubectl get events