更新时间:2022-05-10 GMT+08:00
分享

创建PersistentVolumeClaim

功能介绍

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

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及以上版本集群,示例如下:
    {
      "apiVersion": "v1",
      "kind": "PersistentVolumeClaim",
      "metadata": {
        "name": "pvc-evs-auto-example",
        "namespace": "development",
        "annotations": {
          "everest.io/disk-volume-type": "SSD"
        },
        "labels": {
          "failure-domain.beta.kubernetes.io/region": "cn-south-1",
          "failure-domain.beta.kubernetes.io/zone": "cn-south-2b"
        }
      },
      "spec": {
        "accessModes": [
          "ReadWriteOnce"
        ],
        "resources": {
          "requests": {
            "storage": "10Gi"
          }
        },
        "storageClassName": "csi-disk"
      }
    }
  • 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": "SAS",
    	"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": "pvc-evs-auto-example",
            "namespace": "development",
            "selfLink": "/api/v1/namespaces/development/persistentvolumeclaims/pvc-evs-auto-example",
            "uid": "045b763b-9a82-4520-bba9-0dfecbdfe383",
            "resourceVersion": "26465",
            "creationTimestamp": "2021-10-14T02:34:05Z",
            "labels": {
                "failure-domain.beta.kubernetes.io/region": "cn-south-1",
                "failure-domain.beta.kubernetes.io/zone": "cn-south-2b"
            },
            "annotations": {
                "everest.io/disk-volume-type": "SSD"
            },
            "finalizers": [
                "kubernetes.io/pvc-protection"
            ]
        },
        "spec": {
            "accessModes": [
                "ReadWriteOnce"
            ],
            "resources": {
                "requests": {
                    "storage": "10Gi"
                }
            },
            "storageClassName": "csi-disk",
            "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": "SAS",
                "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.

异常状态码请参见状态码

分享:

    相关文档

    相关产品

close