To create a Persistent Volume Claim (PVC) in Kubernetes, follow these steps:
-
Create a YAML file for the PVC. For example, you can name it
pvc.yaml. Here is an example configuration:apiVersion: v1 kind: PersistentVolumeClaim metadata: name: my-pvc spec: accessModes: - ReadWriteOnce resources: requests: storage: 1GiIn this example:
- The PVC is named
my-pvc. - It requests 1Gi of storage.
- The access mode is set to
ReadWriteOnce, meaning it can be mounted as read-write by a single node.
- The PVC is named
-
Apply the PVC configuration using the
kubectlcommand:kubectl apply -f pvc.yaml
This command will create the PVC in your Kubernetes cluster. You can check the status of the PVC by running:
kubectl get pvc
This will show you the details of the PVC, including whether it is bound to a Persistent Volume (PV).
