# 动态卷制备

<mark style="color:blue;">**动态卷制备允许按需创建存储卷。**</mark>&#x20;

* 如果没有动态制备，集群管理员必须手动地联系他们的云或存储提供商来创建新的存储卷， 然后在 Kubernetes 集群创建 PersistentVolume 对象来表示这些卷。&#x20;
* <mark style="color:blue;">**动态制备功能消除了集群管理员预先配置存储的需要**</mark>。相反，它在用户请求时自动制备存储。

## 启用动态制备

<mark style="color:orange;">**要启用动态制备功能，集群管理员需要为用户预先创建一个或多个 StorageClass 对象。**</mark> StorageClass 对象定义当动态制备被调用时，哪一个驱动将被使用和哪些参数将被传递给驱动。

以下清单创建了一个 "fast" 存储类，它提供类似 SSD 的永久磁盘：

```yaml
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: fast
provisioner: kubernetes.io/gce-pd
parameters:
  type: pd-ssd
```

## 使用动态卷制备 <a href="#using-dynamic-provisioning" id="using-dynamic-provisioning"></a>

通过在 PersistentVolumeClaim 中包含存储类来请求动态制备的存储：

* 使用 <mark style="color:blue;">**PersistentVolumeClaim**</mark> 对象的 <mark style="color:blue;">**storageClassName**</mark> 字段；
* 这个字段的值必须能够匹配到集群管理员配置的 **StorageClass 名称**。

例如，要选择 “fast” 存储类，用户将创建如下的 PersistentVolumeClaim：

```yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: claim1
spec:
  accessModes:
    - ReadWriteOnce
  storageClassName: fast
  resources:
    requests:
      storage: 30Gi
```

该声明会自动制备一块类似 SSD 的永久磁盘。 在删除该声明后，这个卷也会被销毁。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://bohans.gitbook.io/devops/kubernetes/ji-chu-zhi-shi/kubernetes-cun-chu/storageclass/dong-tai-juan-zhi-bei.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
