Creating a PersistentVolumeClaim
Function
This API is used to create a PersistentVolumeClaim in a specified namespace.
If you use an existing EVS disk to create a PVC, add the associated metadata to the cluster as described in Step 5 of Using an Existing EVS to Create a PVC. This operation ensures that the EVS disks associated with the attached static PV are not deleted when the node or cluster is deleted. If you do not perform the preceding operation when using an existing EVS disk to create a PVC or when creating a static PV or PVC, ensure that the EVS disk associated with the static PV has been detached from the node before you delete the node.
URI
POST /api/v1/namespaces/{namespace}/persistentvolumeclaims
Table 1 describes the parameters of this API.
Request
Request parameters:
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
apiVersion |
Yes |
String |
apiVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. |
|
kind |
Yes |
String |
kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. |
|
metadata |
Yes |
metadata object |
Standard object's metadata. |
|
spec |
Yes |
spec object |
Spec defines the desired characteristics of a volume requested by a pod author. |
|
status |
No |
status object |
Status represents the current information/status of a persistent volume claim. Read-only. |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
accessModes |
No |
Array of strings |
AccessModes contains the actual access modes the volume backing the PVC has. |
|
capacity |
No |
Object |
Represents the actual resources of the underlying volume. |
|
phase |
No |
String |
Phase represents the current phase of PersistentVolumeClaim. |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
volumeName |
No |
String |
VolumeName is the binding reference to the PersistentVolume backing this claim. |
|
accessModes |
Yes |
Array of strings |
AccessModes contains the desired access modes the volume should have. A volume can only be mounted using one access mode at a time, even if it supports many. |
|
resources |
Yes |
resources object |
Resources represents the minimum resources the volume should have. |
|
selector |
No |
selector object |
A label query over volumes to consider for binding. |
|
storageClassName |
No |
String |
Name of the StorageClass required by the claim. The cluster of v1.15 or later which use CCE SCI everest should fill in this filed. For EVS, set "csi-disk". For SFS, set "csi-nas". For OBS, set "csi-obs". For SFS-Turbo, set "csi-sfsturbo". |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
limits |
No |
Object |
Limits describes the maximum amount of compute resources allowed.
NOTE:
Parameter limits is invalid. |
|
requests |
No |
Object |
Requests describes the minimum amount of compute resources required. If Requests is omitted for a container, it defaults to Limits if that is explicitly specified, otherwise to an implementation-defined value.
NOTE:
Except parameter storage, the other parameters (such as CPU and memory) are invalid. |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
matchExpressions |
No |
matchExpressions object |
MatchExpressions is a list of label selector requirements. The requirements are ANDed. |
|
matchLabels |
No |
Object |
MatchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels map is equivalent to an element of matchExpressions, whose key field is "key", the operator is "In", and the values array contains only "value". The requirements are ANDed. |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
key |
No |
String |
Key is the label key that the selector applies to. |
|
operator |
No |
String |
Operator represents a key's relationship to a set of values. Valid operators are In, NotIn, Exists and DoesNotExist. |
|
values |
No |
Array of strings |
Values is an array of string values. If the operator is In or NotIn, the values array must be non-empty. If the operator is Exists or DoesNotExist, the values array must be empty. This array is replaced during a strategic merge patch. |
Request examples (EVS volume):
- The following is an example of a cluster of 1.15 or later:
{ "kind":"PersistentVolumeClaim", "apiVersion":"v1", "metadata":{ "name":"cce-evs-k6m16atm-3ays", "namespace":"default", "selfLink":"/api/v1/namespaces/default/persistentvolumeclaims/cce-evs-k6m16atm-3ays", "uid":"80f111e7-7d7e-4841-bd73-7ef97df0ee51", "creationTimestamp":"2020-02-14T10:30:20Z", "labels":{ "failure-domain.beta.kubernetes.io/region":"cn-north-5", "failure-domain.beta.kubernetes.io/zone":"cn-north-5a" }, "annotations":{ This parameter is mandatory for "everest.io/crypt-key-id":"527cbece-428d-463b-a92c-936a11077b5d", // Mandatory for creating encrypted volumes. If this annotation does not exist or is not set as defined here, the volume is not encrypted. "everest.io/disk-volume-type":"SATA" }, "finalizers":[ "kubernetes.io/pvc-protection" ] }, "spec":{ "accessModes":[ "ReadWriteOnce" ], "resources":{ "requests":{ "storage":"10Gi" } }, "storageClassName":"csi-disk", "volumeMode":"Filesystem" } } - Example for clusters of version 1.13 or earlier:
{ "apiVersion": "v1", "kind": "PersistentVolumeClaim", "metadata": { "name": "db-mysql", "namespace": "default", "annotations": { "paas.storage.io/cryptKeyId": "1ed68cb7-b09b-423c-8d66-fdd2e063769d", //The annotation specifies whether to encrypt the password. If this annotation does not exist, the password is not encrypted. "volume.beta.kubernetes.io/storage-class": "sata", "volume.beta.kubernetes.io/storage-provisioner": "flexvolume-huawei.com/fuxivol" }, "labels": { "failure-domain.beta.kubernetes.io/region": "cn-north-4", "failure-domain.beta.kubernetes.io/zone": "cn-north-4a" } }, "spec": { "accessModes": [ "ReadWriteMany" ], "resources": { "requests": { "storage": "10Gi" } } } }
Request examples (SFS file system):
- The following is an example of a cluster of 1.15 or later:
{ "apiVersion": "v1", "kind": "PersistentVolumeClaim", "metadata": { "annotations": { "everest.io/crypt-key-id": "3cfaea47-eb9b-4c68-b108-86fe399aebaf", "everest.io/crypt-domain-id": "fff357e41a3a4a0d88e821f35194d110", "everest.io/crypt-alias": "sfs/default" }, "name": "pvc-158167040158916159-test-sfs-0", "namespace": "default", }, "spec": { "accessModes": [ "ReadWriteMany" ], "resources": { "requests": { "storage": "10Gi" } }, "storageClassName": "csi-nas", "volumeMode": "Filesystem", "volumeName": "pvc-1c933c44-1f47-41a4-9353-3800a21cab6b" } } - Example for clusters of version 1.13 or earlier:
{ "apiVersion": "v1", "kind": "PersistentVolumeClaim", "metadata": { "name": "sfs-pvc", "namespace": "default", "annotations": { "paas.storage.io/cryptAlias": "sfs/default", // The three annotations in red are mandatory for creating encrypted volumes. If the three annotations do not exist or only some of them exist, volumes are not encrypted. "paas.storage.io/cryptDomainId": "fff357e41a3a4a0d88e821f35194d110", "paas.storage.io/cryptKeyId": "3cfaea47-eb9b-4c68-b108-86fe399aebaf", "volume.beta.kubernetes.io/storage-class": "nfs-rw", "volume.beta.kubernetes.io/storage-provisioner": "flexvolume-huawei.com/fuxinfs" } }, "spec": { "accessModes": [ "ReadWriteMany" ], "resources": { "requests": { "storage": "10Gi" } } } }
Response
Response parameters:
For the description about response parameters, see Table 2.
Response example (EVS volume):
- The following is an example of a cluster of 1.15 or later:
{ "kind":"PersistentVolumeClaim", "apiVersion":"v1", "metadata":{ "name":"cce-evs-k6m16atm-3ays", "namespace":"default", "selfLink":"/api/v1/namespaces/default/persistentvolumeclaims/cce-evs-k6m16atm-3ays", "uid":"80f111e7-7d7e-4841-bd73-7ef97df0ee51", "resourceVersion":"2287083", "creationTimestamp":"2020-02-14T10:30:20Z", "labels":{ "failure-domain.beta.kubernetes.io/region":"cn-north-5", "failure-domain.beta.kubernetes.io/zone":"cn-north-5a" }, "annotations":{ "everest.io/crypt-key-id":"527cbece-428d-463b-a92c-936a11077b5d",// If the volume is encrypted, this parameter is displayed. "everest.io/disk-volume-type":"SATA" }, "finalizers":[ "kubernetes.io/pvc-protection" ] }, "spec":{ "accessModes":[ "ReadWriteOnce" ], "resources":{ "requests":{ "storage":"10Gi" } }, "storageClassName":"csi-disk", "volumeName": "pvc-d34f6a93-9eba-4a33-9320-8fa4addd3753", "volumeMode":"Filesystem" }, "status":{ "phase":"Pending" } }
- Example YAML file for clusters of version 1.13 or earlier:
{ "kind": "PersistentVolumeClaim", "apiVersion": "v1", "metadata": { "name": "db-mysql", "namespace": "default", "selfLink": "/api/v1/namespaces/default/persistentvolumeclaims/db-mysql", "uid": "ac34af93-8cdd-11e8-8ee0-fa163e49263c", "resourceVersion": "4197709", "creationTimestamp": "2018-07-21T12:00:33Z", "labels": { "failure-domain.beta.kubernetes.io/region": "cn-north-4", "failure-domain.beta.kubernetes.io/zone": "cn-north-4a" }, "annotations": { "paas.storage.io/cryptKeyId": "1ed68cb7-b09b-423c-8d66-fdd2e063769d" // If the volume is encrypted, this parameter is displayed. "pv.kubernetes.io/bind-completed": "yes", "pv.kubernetes.io/bound-by-controller": "yes", "volume.beta.kubernetes.io/storage-class": "sata", "volume.beta.kubernetes.io/storage-provisioner": "flexvolume-huawei.com/fuxivol" } }, "spec": { "accessModes": [ "ReadWriteMany" ], "resources": { "requests": { "storage": "10Gi" } }, "volumeName": "pvc-ac34af93-8cdd-11e8-8ee0-fa163e49263c", "volumeNamespace": "default" }, "status": { "phase": "Bound", "accessModes": [ "ReadWriteMany" ], "capacity": { "storage": "10Gi" } } }
Status Code
Table 8 describes the status code of this API.
|
Status Code |
Description |
|---|---|
|
201 |
The request has been fulfilled, resulting in the creation of a new resource. |
For the description about error status codes, see Status Code.
Last Article: PersistentVolumeClaim
Next Article: Deleting a Specified PersistentVolumeClaim
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.