WalzoneInterview Prep
πŸ“ž Interviewing soon? Practice with a realistic AI mock phone interview β€” it calls you, then scores you. First 15 min FREE β†’

Kubernetes Β· Intermediate Β· question 28 of 100

How does Kubernetes handle storage using Persistent Volumes (PV) and Persistent Volume Claims (PVC)?

πŸ“• Buy this interview preparation book: 100 Kubernetes questions & answers β€” PDF + EPUB for $5

In Kubernetes, Persistent Volumes (PVs) and Persistent Volume Claims (PVCs) are used to provide persistent storage for containerized applications. PVs are networked storage resources that are provisioned by an administrator and made available to the cluster, while PVCs are requests for storage resources made by users or applications.

The process of using PVs and PVCs involves the following steps:

Provision a Persistent Volume: An administrator creates a PV by defining its properties, such as capacity, access mode, and storage class. The PV can be backed by various types of storage resources, such as local storage, network file systems, or cloud storage.

Create a Persistent Volume Claim: A user or application creates a PVC by specifying the desired amount of storage, access mode, and storage class. The PVC is a request for a specific amount of storage that matches the properties of a PV.

Bind the Persistent Volume Claim to a Persistent Volume: When a PVC is created, Kubernetes searches for a suitable PV that matches the storage request. If a suitable PV is found, Kubernetes binds the PVC to the PV.

Mount the Persistent Volume to a Container: Once a PVC is bound to a PV, it can be mounted to a container in a Pod as a volume. The container can then read from and write to the volume as if it were a local file system.

Here is an example of how to create a PV and a PVC using YAML files:

\# persistent-volume.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
  name: my-pv
spec:
  capacity:
    storage: 1Gi
  accessModes:
  - ReadWriteOnce
  persistentVolumeReclaimPolicy: Retain
  storageClassName: my-storage-class
  hostPath:
    path: /data

\# persistent-volume-claim.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: my-pvc
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
  storageClassName: my-storage-class

In this example, we create a PV with a capacity of 1 gigabyte and a host path of /data. We also create a PVC that requests 1 gigabyte of storage and uses the my-storage-class storage class. The PVC is bound to the PV based on its capacity and storage class.

In conclusion, Kubernetes provides a powerful and flexible storage system using Persistent Volumes (PVs) and Persistent Volume Claims (PVCs). By using PVs and PVCs, users and applications can request and use storage resources in a standard and consistent way, regardless of the underlying storage technology. This allows Kubernetes to provide a unified storage management experience, whether the storage resources are local, networked, or cloud-based.

Reading is step one. Saying it out loud is the interview. Our AI interviewer calls your phone and runs a realistic Kubernetes interview β€” then scores it.
πŸ“ž Practice Kubernetes β€” free 15 min
πŸ“• Buy this interview preparation book: 100 Kubernetes questions & answers β€” PDF + EPUB for $5

All 100 Kubernetes questions Β· All topics