---
title: "创建PV"
method: POST
path: "/k8s/cluster/{id}/pvs"
tags: ["K8s存储管理-PV"]
---

# 创建PV

`POST /k8s/cluster/{id}/pvs`

在集群中创建新的PV

## Path parameters

- `id` integer, required

## Headers

- `Authorization` string, required

## Request body

- ModelCreatePVRequest
  - `accessModes` string[], required — 访问模式
  - `capacity` object, required — 容量
  - `labels` object — 标签
  - `mountOptions` string[] — 挂载选项
  - `name` string, required — PV名称
  - `nodeAffinity` ModelPVNodeAffinity
    - `required` ModelPVNodeSelector
      - `nodeSelectorTerms` ModelPVNodeSelectorTerm[] — 节点选择器条件
        - `matchExpressions` ModelPVNodeSelectorRequirement[] — 匹配表达式
          - `key` string — 键
          - `operator` string — 操作符
          - `values` string[] — 值
        - `matchFields` ModelPVNodeSelectorRequirement[] — 匹配字段
          - `key` string — 键
          - `operator` string — 操作符
          - `values` string[] — 值
  - `persistentVolumeSource` ModelPVSourceSpec, required
    - `awsElasticBlockStore` ModelPVAWSElasticBlockStoreVolumeSource
      - `fsType` string — 文件系统类型
      - `partition` integer — 分区
      - `readOnly` boolean — 只读
      - `volumeID` string — 卷ID
    - `csi` ModelPVCSIVolumeSource
      - `driver` string — 驱动名称
      - `fsType` string — 文件系统类型
      - `readOnly` boolean — 只读
      - `volumeAttributes` object — 卷属性
      - `volumeHandle` string — 卷句柄
    - `hostPath` ModelPVHostPathVolumeSource
      - `path` string — 主机路径
      - `type` string — 类型
    - `iscsi` ModelPVISCSIVolumeSource
      - `fsType` string — 文件系统类型
      - `iqn` string — IQN
      - `iscsiInterface` string — iSCSI接口
      - `lun` integer — LUN
      - `portals` string[] — 门户列表
      - `readOnly` boolean — 只读
      - `targetPortal` string — 目标门户
    - `local` ModelPVLocalVolumeSource
      - `fsType` string — 文件系统类型
      - `path` string — 本地路径
    - `nfs` ModelPVNFSVolumeSource
      - `path` string — NFS路径
      - `readOnly` boolean — 只读
      - `server` string — NFS服务器
  - `reclaimPolicy` string — 回收策略
  - `storageClassName` string — 存储类名称
  - `volumeMode` string — 卷模式

## Response `200`

OK

- object
  - `code` integer — 状态码
  - `data` object — 返回的数据
    - `accessModes` string[] — 访问模式
    - `capacity` string — 总量
    - `claimRef` ModelPVClaimRef
      - `apiVersion` string — API版本
      - `kind` string — 类型
      - `name` string — 名称
      - `namespace` string — 命名空间
      - `uid` string — UID
    - `createdAt` string — 创建时间
    - `labels` object — 标签
    - `mountOptions` string[] — 挂载选项
    - `name` string — PV名称
    - `nodeAffinity` ModelPVNodeAffinity
      - `required` ModelPVNodeSelector
        - `nodeSelectorTerms` ModelPVNodeSelectorTerm[] — 节点选择器条件
          - `matchExpressions` ModelPVNodeSelectorRequirement[] — 匹配表达式
            - `key` string — 键
            - `operator` string — 操作符
            - `values` string[] — 值
          - `matchFields` ModelPVNodeSelectorRequirement[] — 匹配字段
            - `key` string — 键
            - `operator` string — 操作符
            - `values` string[] — 值
    - `persistentVolumeSource` ModelPVSource
      - `awsElasticBlockStore` ModelPVAWSElasticBlockStoreVolumeSource
        - `fsType` string — 文件系统类型
        - `partition` integer — 分区
        - `readOnly` boolean — 只读
        - `volumeID` string — 卷ID
      - `csi` ModelPVCSIVolumeSource
        - `driver` string — 驱动名称
        - `fsType` string — 文件系统类型
        - `readOnly` boolean — 只读
        - `volumeAttributes` object — 卷属性
        - `volumeHandle` string — 卷句柄
      - `hostPath` ModelPVHostPathVolumeSource
        - `path` string — 主机路径
        - `type` string — 类型
      - `iscsi` ModelPVISCSIVolumeSource
        - `fsType` string — 文件系统类型
        - `iqn` string — IQN
        - `iscsiInterface` string — iSCSI接口
        - `lun` integer — LUN
        - `portals` string[] — 门户列表
        - `readOnly` boolean — 只读
        - `targetPortal` string — 目标门户
      - `local` ModelPVLocalVolumeSource
        - `fsType` string — 文件系统类型
        - `path` string — 本地路径
      - `nfs` ModelPVNFSVolumeSource
        - `path` string — NFS路径
        - `readOnly` boolean — 只读
        - `server` string — NFS服务器
    - `reclaimPolicy` string — 回收策略 Retain/Delete/Recycle
    - `status` string — 状态 Available/Bound/Released/Failed
    - `storageClass` string — 存储类型
    - `volumeMode` string — 卷模式
  - `message` string — 提示信息

## Other responses

- `400` — Bad Request
- `401` — Unauthorized
- `500` — Internal Server Error

---

[API](https://skmtc.net/opsre/apis/devops.md) · [All operations](https://skmtc.net/opsre/apis/devops/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/opsre/devops/revisions/25cac8835c4c/schema)
