223 lines
8.9 KiB
Markdown
223 lines
8.9 KiB
Markdown
---
|
||
title: 动态卷制备
|
||
content_type: concept
|
||
weight: 50
|
||
---
|
||
<!--
|
||
reviewers:
|
||
- saad-ali
|
||
- jsafrane
|
||
- thockin
|
||
- msau42
|
||
title: Dynamic Volume Provisioning
|
||
content_type: concept
|
||
weight: 50
|
||
-->
|
||
|
||
<!-- overview -->
|
||
|
||
<!--
|
||
Dynamic volume provisioning allows storage volumes to be created on-demand.
|
||
Without dynamic provisioning, cluster administrators have to manually make
|
||
calls to their cloud or storage provider to create new storage volumes, and
|
||
then create [`PersistentVolume` objects](/docs/concepts/storage/persistent-volumes/)
|
||
to represent them in Kubernetes. The dynamic provisioning feature eliminates
|
||
the need for cluster administrators to pre-provision storage. Instead, it
|
||
automatically provisions storage when it is requested by users.
|
||
-->
|
||
动态卷制备允许按需创建存储卷。
|
||
如果没有动态制备,集群管理员必须手动地联系他们的云或存储提供商来创建新的存储卷,
|
||
然后在 Kubernetes 集群创建
|
||
[`PersistentVolume` 对象](/zh-cn/docs/concepts/storage/persistent-volumes/)来表示这些卷。
|
||
动态制备功能消除了集群管理员预先配置存储的需要。相反,它在用户请求时自动制备存储。
|
||
|
||
<!-- body -->
|
||
|
||
<!--
|
||
## Background
|
||
-->
|
||
## 背景 {#background}
|
||
|
||
<!--
|
||
The implementation of dynamic volume provisioning is based on the API object `StorageClass`
|
||
from the API group `storage.k8s.io`. A cluster administrator can define as many
|
||
`StorageClass` objects as needed, each specifying a *volume plugin* (aka
|
||
*provisioner*) that provisions a volume and the set of parameters to pass to
|
||
that provisioner when provisioning.
|
||
-->
|
||
动态卷制备的实现基于 `storage.k8s.io` API 组中的 `StorageClass` API 对象。
|
||
集群管理员可以根据需要定义多个 `StorageClass` 对象,每个对象指定一个**卷插件**(又名 **provisioner**),
|
||
卷插件向卷制备商提供在创建卷时需要的数据卷信息及相关参数。
|
||
|
||
<!--
|
||
A cluster administrator can define and expose multiple flavors of storage (from
|
||
the same or different storage systems) within a cluster, each with a custom set
|
||
of parameters. This design also ensures that end users don't have to worry
|
||
about the complexity and nuances of how storage is provisioned, but still
|
||
have the ability to select from multiple storage options.
|
||
-->
|
||
集群管理员可以在集群中定义和公开多种存储(来自相同或不同的存储系统),每种都具有自定义参数集。
|
||
该设计也确保终端用户不必担心存储制备的复杂性和细微差别,但仍然能够从多个存储选项中进行选择。
|
||
|
||
<!--
|
||
More information on storage classes can be found
|
||
[here](/docs/concepts/storage/storage-classes/).
|
||
-->
|
||
点击[这里](/zh-cn/docs/concepts/storage/storage-classes/)查阅有关存储类的更多信息。
|
||
|
||
<!--
|
||
## Enabling Dynamic Provisioning
|
||
-->
|
||
## 启用动态卷制备 {#enabling-dynamic-provisioning}
|
||
|
||
<!--
|
||
To enable dynamic provisioning, a cluster administrator needs to pre-create
|
||
one or more StorageClass objects for users.
|
||
StorageClass objects define which provisioner should be used and what parameters
|
||
should be passed to that provisioner when dynamic provisioning is invoked.
|
||
The name of a StorageClass object must be a valid
|
||
[DNS subdomain name](/docs/concepts/overview/working-with-objects/names#dns-subdomain-names).
|
||
|
||
The following manifest creates a storage class "slow" which provisions standard
|
||
disk-like persistent disks.
|
||
-->
|
||
要启用动态制备功能,集群管理员需要为用户预先创建一个或多个 `StorageClass` 对象。
|
||
`StorageClass` 对象定义当动态制备被调用时,哪一个驱动将被使用和哪些参数将被传递给驱动。
|
||
StorageClass 对象的名字必须是一个合法的
|
||
[DNS 子域名](/zh-cn/docs/concepts/overview/working-with-objects/names#dns-subdomain-names)。
|
||
以下清单创建了一个 `StorageClass` 存储类 "slow",它提供类似标准磁盘的永久磁盘。
|
||
|
||
```yaml
|
||
apiVersion: storage.k8s.io/v1
|
||
kind: StorageClass
|
||
metadata:
|
||
name: slow
|
||
provisioner: kubernetes.io/gce-pd
|
||
parameters:
|
||
type: pd-standard
|
||
```
|
||
|
||
<!--
|
||
The following manifest creates a storage class "fast" which provisions
|
||
SSD-like persistent disks.
|
||
-->
|
||
以下清单创建了一个 "fast" 存储类,它提供类似 SSD 的永久磁盘。
|
||
|
||
```yaml
|
||
apiVersion: storage.k8s.io/v1
|
||
kind: StorageClass
|
||
metadata:
|
||
name: fast
|
||
provisioner: kubernetes.io/gce-pd
|
||
parameters:
|
||
type: pd-ssd
|
||
```
|
||
|
||
<!--
|
||
## Using Dynamic Provisioning
|
||
-->
|
||
## 使用动态卷制备 {#using-dynamic-provisioning}
|
||
|
||
<!--
|
||
Users request dynamically provisioned storage by including a storage class in
|
||
their `PersistentVolumeClaim`. Before Kubernetes v1.6, this was done via the
|
||
`volume.beta.kubernetes.io/storage-class` annotation. However, this annotation
|
||
is deprecated since v1.9. Users now can and should instead use the
|
||
`storageClassName` field of the `PersistentVolumeClaim` object. The value of
|
||
this field must match the name of a `StorageClass` configured by the
|
||
administrator (see [below](#enabling-dynamic-provisioning)).
|
||
-->
|
||
用户通过在 `PersistentVolumeClaim` 中包含存储类来请求动态制备的存储。
|
||
在 Kubernetes v1.9 之前,这通过 `volume.beta.kubernetes.io/storage-class` 注解实现。
|
||
然而,这个注解自 v1.6 起就不被推荐使用了。
|
||
用户现在能够而且应该使用 `PersistentVolumeClaim` 对象的 `storageClassName` 字段。
|
||
这个字段的值必须能够匹配到集群管理员配置的 `StorageClass` 名称(见[下面](#enabling-dynamic-provisioning))。
|
||
|
||
<!--
|
||
To select the "fast" storage class, for example, a user would create the
|
||
following PersistentVolumeClaim:
|
||
-->
|
||
例如,要选择 “fast” 存储类,用户将创建如下的 PersistentVolumeClaim:
|
||
|
||
```yaml
|
||
apiVersion: v1
|
||
kind: PersistentVolumeClaim
|
||
metadata:
|
||
name: claim1
|
||
spec:
|
||
accessModes:
|
||
- ReadWriteOnce
|
||
storageClassName: fast
|
||
resources:
|
||
requests:
|
||
storage: 30Gi
|
||
```
|
||
|
||
<!--
|
||
This claim results in an SSD-like Persistent Disk being automatically
|
||
provisioned. When the claim is deleted, the volume is destroyed.
|
||
-->
|
||
该声明会自动制备一块类似 SSD 的永久磁盘。
|
||
在删除该声明后,这个卷也会被销毁。
|
||
|
||
<!--
|
||
## Defaulting Behavior
|
||
-->
|
||
## 设置默认值的行为 {#defaulting-behavior}
|
||
|
||
<!--
|
||
Dynamic provisioning can be enabled on a cluster such that all claims are
|
||
dynamically provisioned if no storage class is specified. A cluster administrator
|
||
can enable this behavior by:
|
||
-->
|
||
可以在集群上启用动态卷制备,以便在未指定存储类的情况下动态设置所有声明。
|
||
集群管理员可以通过以下方式启用此行为:
|
||
|
||
<!--
|
||
- Marking one `StorageClass` object as *default*;
|
||
- Making sure that the [`DefaultStorageClass` admission controller](/docs/reference/access-authn-authz/admission-controllers/#defaultstorageclass)
|
||
is enabled on the API server.
|
||
-->
|
||
- 标记一个 `StorageClass` 为 **默认**;
|
||
- 确保 [`DefaultStorageClass` 准入控制器](/zh-cn/docs/reference/access-authn-authz/admission-controllers/#defaultstorageclass)在
|
||
API 服务器端被启用。
|
||
|
||
<!--
|
||
An administrator can mark a specific `StorageClass` as default by adding the
|
||
[`storageclass.kubernetes.io/is-default-class` annotation](/docs/reference/labels-annotations-taints/#storageclass-kubernetes-io-is-default-class) to it.
|
||
When a default `StorageClass` exists in a cluster and a user creates a
|
||
`PersistentVolumeClaim` with `storageClassName` unspecified, the
|
||
`DefaultStorageClass` admission controller automatically adds the
|
||
`storageClassName` field pointing to the default storage class.
|
||
-->
|
||
管理员可以通过向其添加
|
||
[`storageclass.kubernetes.io/is-default-class` 注解](/zh-cn/docs/reference/labels-annotations-taints/#storageclass-kubernetes-io-is-default-class)
|
||
来将特定的 `StorageClass` 标记为默认。
|
||
当集群中存在默认的 `StorageClass` 并且用户创建了一个未指定 `storageClassName` 的 `PersistentVolumeClaim` 时,
|
||
`DefaultStorageClass` 准入控制器会自动向其中添加指向默认存储类的 `storageClassName` 字段。
|
||
|
||
<!--
|
||
Note that there can be at most one *default* storage class on a cluster, or
|
||
a `PersistentVolumeClaim` without `storageClassName` explicitly specified cannot
|
||
be created.
|
||
-->
|
||
请注意,集群上最多只能有一个 **默认** 存储类,否则无法创建没有明确指定
|
||
`storageClassName` 的 `PersistentVolumeClaim`。
|
||
|
||
<!--
|
||
## Topology Awareness
|
||
-->
|
||
## 拓扑感知 {#topology-awareness}
|
||
|
||
<!--
|
||
In [Multi-Zone](/docs/setup/best-practices/multiple-zones/) clusters, Pods can be spread across
|
||
Zones in a Region. Single-Zone storage backends should be provisioned in the Zones where
|
||
Pods are scheduled. This can be accomplished by setting the
|
||
[Volume Binding Mode](/docs/concepts/storage/storage-classes/#volume-binding-mode).
|
||
-->
|
||
在[多可用区](/zh-cn/docs/setup/best-practices/multiple-zones/)集群中,Pod 可以被分散到某个区域的多个可用区。
|
||
单可用区存储后端应该被制备到 Pod 被调度到的可用区。
|
||
这可以通过设置[卷绑定模式](/zh-cn/docs/concepts/storage/storage-classes/#volume-binding-mode)来实现。
|
||
|
||
|