Docker Storage and Kubernetes Integration 📦
Docker Storage Overview 🐳
Volume Creation
- Auto-creation: Docker automatically creates a volume if not explicitly defined.
- Newer Way to Mount Volumes: Utilize modern methods for mounting volumes in Docker containers.
Types of Docker Storage
- Local Storage: Mounting a local folder inside the container as a volume.
- Third-Party Storage: Integration with external storage solutions such as AWS EBS volumes.
Kubernetes Storage 🗂️
Kubernetes Runtime Interfaces
- Container Runtime Interface (CRI): Integrates container runtimes.
- Container Network Interface (CNI): Integrates network plugins.
- Container Storage Interface (CSI): Integrates storage plugins.
Host Folder Mounting
- Mounting a Host Folder: Example of mounting a host path inside the container as a volume.
volumeMounts: - mountPath: /data name: data-volume volumes: - name: data-volume hostPath: path: /data
- Note: This method is not recommended for multi-node clusters. Instead, use third-party solutions like AWS EBS, Azure Disk, or Google Cloud Persistent Disk to manage data centrally.
Persistent Volumes (PV) and Persistent Volume Claims (PVC)
Creating a Persistent Volume (PV)
- Mount AWS EBS Volume in all nodes for equal data persistence.
apiVersion: v1 kind: PersistentVolume metadata: name: example-pv spec: capacity: storage: 5Gi accessModes: - ReadWriteOnce persistentVolumeReclaimPolicy: Retain storageClassName: standard awsElasticBlockStore: volumeID: <volume-id> fsType: ext4
Access Modes for PV
- HostPath: Example
/tmp/data
is not recommended for production. Prefer third-party storage solutions.
Creating a Persistent Volume Claim (PVC)
- Example PVC for claiming the PV.
apiVersion: v1 kind: PersistentVolumeClaim metadata: name: example-pvc spec: accessModes: - ReadWriteOnce resources: requests: storage: 500Mi storageClassName: standard
Reclaim Policies
- Delete: Deletes the PV when PVC is deleted.
- Recycle: Makes PV available and flushes data when PVC is deleted.
- Retain: Retains data and PV is not available for new claims when PVC is deleted.
Attaching PV & PVC to a Pod
- Specify the PVC claim name under
persistentVolumeClaim
section in the volumes section of the pod definition file.apiVersion: v1 kind: Pod metadata: name: example-pod spec: containers: - name: example-container image: nginx volumeMounts: - mountPath: /data name: data-volume volumes: - name: data-volume persistentVolumeClaim: claimName: example-pvc
Storage Class (Dynamic Storage) 📦
-
Use
StorageClass
for dynamic provisioning of storage.apiVersion: storage.k8s.io/v1 kind: StorageClass metadata: name: standard provisioner: kubernetes.io/aws-ebs parameters: type: gp2
-
Check available storage classes:
kubectl get storageclass