文档首页 > > API参考> Kubernetes API> PersistentVolumeClaim> 创建PersistentVolumeClaim

创建PersistentVolumeClaim

分享
更新时间:2020/10/10 GMT+08:00

功能介绍

该API用于在指定的Namespace下创建PersistentVolumeClaim。

使用已有的EVS创建PVC时,请参照CCE用户指南中使用云硬盘存储章节的使用已有的EVS创建PVC步骤5为集群增加关联的metadata,以确保在删除节点或集群时避免删除已挂载的静态PV关联的EVS盘。若不执行上述操作或创建静态PV/PVC时没有执行过上述操作,请务必确保删除节点前,提前将静态PV关联的云硬盘从节点上卸载。

URI

POST /api/v1/namespaces/{namespace}/persistentvolumeclaims

表1 描述该API的参数。

表1 参数描述

参数

是否必选

描述

namespace

Yes

Object name and auth scope, such as for teams and projects.

pretty

No

If 'true', then the output is pretty printed.

请求消息

请求参数:

表2 请求参数

参数

是否必选

参数类型

描述

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.

表3 status字段数据结构说明

参数

是否必选

参数类型

描述

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.

表4 spec字段数据结构说明

参数

是否必选

参数类型

描述

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".

表5 resources字段数据结构说明

参数

是否必选

参数类型

描述

limits

No

Object

Limits describes the maximum amount of compute resources allowed.

说明:

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.

说明:

Except parameter storage, the other parameters (such as CPU and memory) are invalid.

表6 selector字段数据结构说明

参数

是否必选

参数类型

描述

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.

表7 matchExpressions字段数据结构说明

参数

是否必选

参数类型

描述

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.

云硬盘存储卷请求示例

  • 1.15及以上版本集群,示例如下:
    {
        "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":{
                "everest.io/crypt-key-id":"527cbece-428d-463b-a92c-936a11077b5d", //创建加密卷必需,若无或不全,则不加密;
                "everest.io/disk-volume-type":"SATA"
            },
            "finalizers":[
                "kubernetes.io/pvc-protection"
            ]
        },
        "spec":{
            "accessModes":[
                "ReadWriteOnce"
            ],
            "resources":{
                "requests":{
                    "storage":"10Gi"
                }
            },
            "storageClassName":"csi-disk",
            "volumeMode":"Filesystem"
        }
    }
  • 1.13及之前版本示例:
    {
        "apiVersion": "v1",
        "kind": "PersistentVolumeClaim",
        "metadata": {
            "name": "db-mysql",
            "namespace": "default",
            "annotations": {
            "paas.storage.io/cryptKeyId": "1ed68cb7-b09b-423c-8d66-fdd2e063769d",     //此annotation表明是否加密,若无,则不加密;
    	"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"
                }
            }
        }
    }

文件存储卷请求示例

  • 1.15及以上版本集群,示例如下:
    {
        "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"
        }
    }
  • 1.13及之前集群版本示例:
    {
        "apiVersion": "v1",
        "kind": "PersistentVolumeClaim",
        "metadata": {
            "name": "sfs-pvc",
            "namespace": "default",
            "annotations": {   
            "paas.storage.io/cryptAlias": "sfs/default" ,           //红色字体部分三个annotation是创建加密卷必需,若无或不全,则不加密;
            "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"
                }
            }
        }
    }

响应消息

响应参数:

响应参数的详细描述请参见14.2 Table2 Request parameters.

云硬盘存储卷响应示例:

  • 1.15及以上版本集群,示例如下:
    {
        "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",//若为加密卷,则存在
                "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"
        }
    }
  • 1.13及之前版本yaml示例:
    {
        "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"   //若为加密卷,则存在
                "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"
            }
        }
    }

状态码

表8描述API的状态码。

表8 状态码

状态码

描述

201

The request has been fulfilled, resulting in the creation of a new resource.

异常状态码请参见状态码

分享:

    相关文档

    相关产品

文档是否有解决您的问题?

提交成功!非常感谢您的反馈,我们会继续努力做到更好!
反馈提交失败,请稍后再试!

*必选

请至少选择或填写一项反馈信息

字符长度不能超过200

提交反馈 取消

如您有其它疑问,您也可以通过华为云社区问答频道来与我们联系探讨

智能客服提问云社区提问