Know how to configure applications with persistent storage

Context: CKA certification command examples.

Know how to configure applications with persistent storage

Configuring applications with persistent storage is an essential aspect of managing containerized applications. In the context of the Certified Kubernetes Administrator (CKA) certification, you may encounter tasks related to persistent storage. Here are some command examples that can help you configure applications with persistent storage in Kubernetes:

  1. Create a PersistentVolume (PV):
apiVersion: v1
kind: PersistentVolume
metadata:
name: my-pv
spec:
capacity:
storage: 1Gi
accessModes: - ReadWriteOnce   
persistentVolumeReclaimPolicy: Retain
storageClassName: slow
hostPath: path: /data/my-pv

Explanation: This YAML manifest creates a PersistentVolume named "my-pv" with a storage capacity of 1GB. It uses the hostPath volume plugin to store data on the host's file system.

  1. Create a PersistentVolumeClaim (PVC):
apiVersion: v1
kind: PersistentVolumeClaim
metadata: name: my-pvc
spec:
accessModes: - ReadWriteOnce
resources:
requests:
storage: 1Gi
storageClassName: slow

Explanation: This YAML manifest creates a PersistentVolumeClaim named "my-pvc" requesting 1GB of storage with access mode ReadWriteOnce. It references the "slow" storageClassName, which matches the storageClassName used in the PV.

  1. Mount the PVC in a Pod:
apiVersion: v1
kind: Pod
metadata:
name: my-pod
spec:
containers:
- name: my-container
image: my-image
volumeMounts:
- name: my-volume
mountPath: /data
volumes:
- name: my-volume
persistentVolumeClaim:
claimName: my-pvc

Explanation: This YAML manifest creates a Pod named "my-pod" with a container named "my-container". It mounts the PVC "my-pvc" to the path "/data" inside the container.

These examples cover the basic steps for configuring applications with persistent storage in Kubernetes. Remember to adjust the YAML manifests according to your specific requirements, such as storage class, access modes, and storage capacity.

You should also read: