• Cloud Container Engine

cce
  1. Help Center
  2. Cloud Container Engine
  3. API Reference 2.0
  4. Kubernetes API
  5. PersistentVolumeClaim
  6. Creating a PersistentVolumeClaim

Creating a PersistentVolumeClaim

Function

This API is used to create a PersistentVolumeClaim object under a specified Namespace.

URI

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

Table 1 describes the parameters of this API.

Table 1 Parameter description

Parameter

Mandatory

Description

namespace

Yes

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

pretty

No

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

Request

Request parameters:

Table 2 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

3.1 Table11 Data structure of the metadata field

Standard object's metadata.

spec

Yes

Table 4

Spec defines the desired characteristics of a volume requested by a pod author.

status

No

Table 3

Status represents the current information/status of a persistent volume claim. Read-only.

Table 3 Data structure of the status field

Parameter

Mandatory

Type

Description

accessModes

No

String array

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.

Table 4 Data structure of the spec field

Parameter

Mandatory

Type

Description

volumeName

No

String

VolumeName is the binding reference to the PersistentVolume backing this claim.

This parameter is required when you use flexVolume to create a PV for an existing cloud storage.

accessModes

Yes

String array

AccessModes contains the desired access modes the volume should have.

resources

Yes

Table 5

Resources represents the minimum resources the volume should have.

selector

No

Table 6

A label query over volumes to consider for binding.

storageClassName

No

String

Name of the StorageClass required by the claim.

volumeNamespace

No

String

Namespace of the PV, which should be filled with "default".

This parameter is required when you use flexVolume to create a PV for an existing cloud storage.

Table 5 Data structure of the resources field

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.

Table 6 Data structure of the selector field

Parameter

Mandatory

Type

Description

matchExpressions

No

Table 7

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.

Table 7 Data structure of the matchExpressions field

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

String array

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.

Example request:

{
    "apiVersion": "v1",
    "kind": "PersistentVolumeClaim",
    "metadata": {
        "name": "db-mysql-0",
        "namespace": "default"
    },
    "spec": {
        "accessModes": [
            "ReadWriteMany"
        ],
        "resources": {
            "requests": {
                "storage": "1Gi"
            }
        }
    }
}

Response

Response parameters:

For the description about response parameters, see 14.2 Table2 Request parameters.

Example response:

{
    "kind": "PersistentVolumeClaim",
    "apiVersion": "v1",
    "metadata": {
        "name": "db-mysql-0",
        "namespace": "default",
        "selfLink": "/api/v1/namespaces/default/persistentvolumeclaims/db-mysql-0",
        "uid": "86b29e16-23db-11e7-9c83-fa163ec08232",
        "resourceVersion": "1793115",
        "creationTimestamp": "2017-04-18T02:05:42Z"
    },
    "spec": {
        "accessModes": [
            "ReadWriteMany"
        ],
        "resources": {
            "requests": {
                "storage": "1Gi"
            }
        }
    },
    "status": {
        "phase": "Pending"
    }
}

Status Code

Table 8 describes the status code of this API.

Table 8 Status code

Status Code

Description

201

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

For the description about status codes, see Status Codes.