4.10. Persistent volume claims
Each PersistentVolumeClaim object contains a spec and status, which is the specification and status of the persistent volume claim (PVC), for example:
PersistentVolumeClaim object definition example
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: myclaim
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 8Gi
storageClassName: gold
status:
...
4.10.1. Storage classes リンクのコピーリンクがクリップボードにコピーされました!
Claims can optionally request a specific storage class by specifying the storage class’s name in the storageClassName attribute. Only PVs of the requested class, ones with the same storageClassName as the PVC, can be bound to the PVC. The cluster administrator can configure dynamic provisioners to service one or more storage classes. The cluster administrator can create a PV on demand that matches the specifications in the PVC.
The cluster administrator can also set a default storage class for all PVCs. When a default storage class is configured, the PVC must explicitly ask for StorageClass or storageClassName annotations set to "" to be bound to a PV without a storage class.
If more than one storage class is marked as default, a PVC can only be created if the storageClassName is explicitly specified. Therefore, only one storage class should be set as the default.
4.10.2. Access modes リンクのコピーリンクがクリップボードにコピーされました!
Claims use the same conventions as volumes when requesting storage with specific access modes.
4.10.3. Resources リンクのコピーリンクがクリップボードにコピーされました!
Claims, such as pods, can request specific quantities of a resource. In this case, the request is for storage. The same resource model applies to volumes and claims.
4.10.4. Claims as volumes リンクのコピーリンクがクリップボードにコピーされました!
Pods access storage by using the claim as a volume. Claims must exist in the same namespace as the pod using the claim. The cluster finds the claim in the pod’s namespace and uses it to get the PersistentVolume backing the claim. The volume is mounted to the host and into the pod, for example:
Mount volume to the host and into the pod example
kind: Pod
apiVersion: v1
metadata:
name: mypod
spec:
containers:
- name: myfrontend
image: dockerfile/nginx
volumeMounts:
- mountPath: "/var/www/html"
name: mypd
volumes:
- name: mypd
persistentVolumeClaim:
claimName: myclaim
- 1
- Path to mount the volume inside the pod.
- 2
- Name of the volume to mount. Do not mount to the container root,
/, or any path that is the same in the host and the container. This can corrupt your host system if the container is sufficiently privileged, such as the host/dev/ptsfiles. It is safe to mount the host by using/host. - 3
- Name of the PVC, that exists in the same namespace, to use.
4.10.5. Viewing PVC usage statistics リンクのコピーリンクがクリップボードにコピーされました!
You can view usage statistics for persistent volume claims (PVCs).
PVC usage statistics command is a Technology Preview feature only. Technology Preview features are not supported with Red Hat production service level agreements (SLAs) and might not be functionally complete. Red Hat does not recommend using them in production. These features provide early access to upcoming product features, enabling customers to test functionality and provide feedback during the development process.
For more information about the support scope of Red Hat Technology Preview features, see the following link:
4.10.5.1. User permissions required to view PVC usage statistics リンクのコピーリンクがクリップボードにコピーされました!
To view PVC usage statistics, you must have the necessary privileges.
To log on with the necessary privileges:
- If you have admin privileges, log on as an admin.
If you do not have admin privileges:
Create and add cluster roles to the user by running the following commands:
$ oc create clusterrole routes-view --verb=get,list --resource=routes $ oc adm policy add-cluster-role-to-user routes-view <user-name>1 $ oc adm policy add-cluster-role-to-user cluster-monitoring-view <user-name>2
4.10.5.2. Viewing PVC usage statistics リンクのコピーリンクがクリップボードにコピーされました!
To view statistics across a cluster, run the following command:
$ oc adm top pvc -AExample command output
NAMESPACE NAME USAGE(%) namespace-1 data-etcd-1 3.82% namespace-1 data-etcd-0 3.81% namespace-1 data-etcd-2 3.81% namespace-2 mypvc-fs-gp3 0.00% default mypvc-fs 98.36%To view PVC usage statistics for a specified namespace, run the following command:
$ oc adm top pvc -n <namespace-name>1 - 1
- Where
<namespace-name>is the name of the specified namespace.
Example command output
NAMESPACE NAME USAGE(%) namespace-1 data-etcd-2 3.81%1 namespace-1 data-etcd-0 3.81% namespace-1 data-etcd-1 3.82%- 1
- In this example, the specified namespace is
namespace-1.
To view usage statistics for a specified PVC and for a specified namespace, run the following command:
$ oc adm top pvc <pvc-name> -n <namespace-name>1 - 1
- Where
<pvc-name>is the name of specified PVC and<namespace-name>is the name of the specified namespace.
Example command output
NAMESPACE NAME USAGE(%) namespace-1 data-etcd-0 3.81%1 - 1
- In this example, the specified namespace is
namespace-1and the specified PVC isdata-etcd-0.