Skip to content

Commit c5f98c6

Browse files
committed
update
1 parent 6871dd9 commit c5f98c6

File tree

1 file changed

+49
-29
lines changed

1 file changed

+49
-29
lines changed

content/zh-cn/docs/tasks/configure-pod-container/configure-persistent-volume-storage.md

Lines changed: 49 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ weight: 60
1313
<!-- overview -->
1414

1515
<!--
16-
This page shows how to configure a Pod to use a
16+
This page shows you how to configure a Pod to use a
1717
{{< glossary_tooltip text="PersistentVolumeClaim" term_id="persistent-volume-claim" >}}
1818
for storage.
1919
Here is a summary of the process:
@@ -27,7 +27,7 @@ PersistentVolume.
2727
2828
1. You create a Pod that uses the above PersistentVolumeClaim for storage.
2929
-->
30-
本文介绍如何配置 Pod 使用
30+
本文将向你介绍如何配置 Pod 使用
3131
{{< glossary_tooltip text="PersistentVolumeClaim" term_id="persistent-volume-claim" >}}
3232
作为存储。
3333
以下是该过程的总结:
@@ -42,7 +42,8 @@ PersistentVolume.
4242
## {{% heading "prerequisites" %}}
4343

4444
<!--
45-
* You need to have a Kubernetes cluster that has only one Node, and the kubectl
45+
* You need to have a Kubernetes cluster that has only one Node, and the
46+
{{< glossary_tooltip text="kubectl" term_id="kubectl" >}}
4647
command-line tool must be configured to communicate with your cluster. If you
4748
do not already have a single-node cluster, you can create one by using
4849
[Minikube](https://minikube.sigs.k8s.io/docs/).
@@ -51,7 +52,8 @@ do not already have a single-node cluster, you can create one by using
5152
[Persistent Volumes](/docs/concepts/storage/persistent-volumes/).
5253
-->
5354

54-
* 你需要一个包含单个节点的 Kubernetes 集群,并且必须配置 kubectl 命令行工具以便与集群交互。
55+
* 你需要一个包含单个节点的 Kubernetes 集群,并且必须配置
56+
{{< glossary_tooltip text="kubectl" term_id="kubectl" >}} 命令行工具以便与集群交互。
5557
如果还没有单节点集群,可以使用
5658
[Minikube](https://minikube.sigs.k8s.io/docs/) 创建一个。
5759
.
@@ -62,19 +64,19 @@ do not already have a single-node cluster, you can create one by using
6264
<!--
6365
## Create an index.html file on your Node
6466
65-
Open a shell to the Node in your cluster. How you open a shell depends on how
66-
you set up your cluster. For example, if you are using Minikube, you can open a
67-
shell to your Node by entering `minikube ssh`.
67+
Open a shell to the single Node in your cluster. How you open a shell depends
68+
on how you set up your cluster. For example, if you are using Minikube, you
69+
can open a shell to your Node by entering `minikube ssh`.
6870
69-
In your shell, create a `/mnt/data` directory:
71+
In your shell on that Node, create a `/mnt/data` directory:
7072
-->
7173
## 在你的节点上创建一个 index.html 文件
7274

73-
打开集群中节点的一个 Shell。
75+
打开集群中的某个节点的 Shell。
7476
如何打开 Shell 取决于集群的设置。
7577
例如,如果你正在使用 Minikube,那么可以通过输入 `minikube ssh` 来打开节点的 Shell。
7678

77-
Shell 中,创建一个 `/mnt/data` 目录:
79+
在该节点的 Shell 中,创建一个 `/mnt/data` 目录:
7880

7981
<!--
8082
# This assumes that your Node uses "sudo" to run commands
@@ -94,7 +96,7 @@ In the `/mnt/data` directory, create an `index.html` file:
9496
# This again assumes that your Node uses "sudo" to run commands
9597
# as the superuser
9698
-->
97-
```
99+
```shell
98100
# 这里再次假定你的节点使用 "sudo" 来以超级用户角色执行命令
99101
sudo sh -c "echo 'Hello from Kubernetes storage' > /mnt/data/index.html"
100102
```
@@ -139,7 +141,7 @@ PersistentVolume uses a file or directory on the Node to emulate network-attache
139141
-->
140142
## 创建 PersistentVolume
141143

142-
在本练习中,你将创建一个 *hostPath* 类型的 PersistentVolume。
144+
在本练习中,你将创建一个 **hostPath** 类型的 PersistentVolume。
143145
Kubernetes 支持用于在单节点集群上开发和测试的 hostPath 类型的 PersistentVolume。
144146
hostPath 类型的 PersistentVolume 使用节点上的文件或目录来模拟网络附加存储。
145147

@@ -149,18 +151,36 @@ would provision a network resource like a Google Compute Engine persistent disk,
149151
an NFS share, or an Amazon Elastic Block Store volume. Cluster administrators can also
150152
use [StorageClasses](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#storageclass-v1-storage)
151153
to set up
152-
[dynamic provisioning](https://kubernetes.io/blog/2016/10/dynamic-provisioning-and-storage-in-kubernetes).
154+
[dynamic provisioning](/blog/2016/10/dynamic-provisioning-and-storage-in-kubernetes).
153155
154156
Here is the configuration file for the hostPath PersistentVolume:
155157
-->
156158
在生产集群中,你不会使用 hostPath。
157159
集群管理员会提供网络存储资源,比如 Google Compute Engine 持久盘卷、NFS 共享卷或 Amazon Elastic Block Store 卷。
158-
集群管理员还可以使用 [StorageClasses](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#storageclass-v1-storage) 来设置[动态提供存储](https://kubernetes.io/blog/2016/10/dynamic-provisioning-and-storage-in-kubernetes)
160+
集群管理员还可以使用
161+
[StorageClasses](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#storageclass-v1-storage)
162+
来设置[动态提供存储](/blog/2016/10/dynamic-provisioning-and-storage-in-kubernetes)
159163

160164
下面是 hostPath PersistentVolume 的配置文件:
161165

162166
{{< codenew file="pods/storage/pv-volume.yaml" >}}
163167

168+
<!--
169+
The configuration file specifies that the volume is at `/mnt/data` on the
170+
cluster's Node. The configuration also specifies a size of 10 gibibytes and
171+
an access mode of `ReadWriteOnce`, which means the volume can be mounted as
172+
read-write by a single Node. It defines the [StorageClass name](/docs/concepts/storage/persistent-volumes/#class)
173+
`manual` for the PersistentVolume, which will be used to bind
174+
PersistentVolumeClaim requests to this PersistentVolume.
175+
-->
176+
配置文件指定卷位于集群节点上的 `/mnt/data` 路径。
177+
配置还指定了卷的容量大小为 10 GB,
178+
访问模式为 `ReadWriteOnce`
179+
这意味着该卷可以被单个节点以读写方式安装。
180+
配置文件还在 PersistentVolume 中定义了
181+
[StorageClass 的名称](/zh-cn/docs/concepts/storage/persistent-volumes/#class)
182+
`manual`。它将用于将 PersistentVolumeClaim 的请求绑定到此 PersistentVolume。
183+
164184
<!--
165185
Create the PersistentVolume:
166186
-->
@@ -216,7 +236,7 @@ Create the PersistentVolumeClaim:
216236
创建 PersistentVolumeClaim:
217237

218238
```shell
219-
kubectl create -f https://k8s.io/examples/pods/storage/pv-claim.yaml
239+
kubectl apply -f https://k8s.io/examples/pods/storage/pv-claim.yaml
220240
```
221241

222242
<!--
@@ -252,7 +272,7 @@ Look at the PersistentVolumeClaim:
252272
-->
253273
查看 PersistentVolumeClaim:
254274

255-
```
275+
```shell
256276
kubectl get pvc task-pv-claim
257277
```
258278

@@ -299,7 +319,7 @@ kubectl apply -f https://k8s.io/examples/pods/storage/pv-pod.yaml
299319
```
300320

301321
<!--
302-
Verify that the Container in the Pod is running;
322+
Verify that the container in the Pod is running;
303323
-->
304324
检查 Pod 中的容器是否运行正常:
305325

@@ -308,7 +328,7 @@ kubectl get pod task-pv-pod
308328
```
309329

310330
<!--
311-
Get a shell to the Container running in your Pod:
331+
Get a shell to the container running in your Pod:
312332
-->
313333
打开一个 Shell 访问 Pod 中的容器:
314334

@@ -326,11 +346,11 @@ hostPath volume:
326346
# Be sure to run these 3 commands inside the root shell that comes from
327347
# running "kubectl exec" in the previous step
328348
-->
329-
```
349+
```shell
330350
# 一定要在上一步 "kubectl exec" 所返回的 Shell 中执行下面三个命令
331-
root@task-pv-pod:/# apt-get update
332-
root@task-pv-pod:/# apt-get install curl
333-
root@task-pv-pod:/# curl localhost
351+
apt update
352+
apt install curl
353+
curl http://localhost/
334354
```
335355

336356
<!--
@@ -374,7 +394,10 @@ In the shell on your Node, remove the file and directory that you created:
374394
如果你还没有连接到集群中节点的 Shell,可以按之前所做操作,打开一个新的 Shell。
375395

376396
在节点的 Shell 上,删除你所创建的目录和文件:
377-
397+
<!--
398+
# This assumes that your Node uses "sudo" to run commands
399+
# as the superuser
400+
-->
378401

379402
```shell
380403
# 这里假定你使用 "sudo" 来以超级用户的角色执行命令
@@ -390,7 +413,6 @@ You can now close the shell to your Node.
390413
<!--
391414
## Mounting the same persistentVolume in two places
392415
-->
393-
394416
## 在两个地方挂载相同的 persistentVolume
395417

396418
{{< codenew file="pods/storage/pv-duplicate.yaml" >}}
@@ -427,8 +449,8 @@ GID 不匹配或缺失将会导致无权访问错误。
427449
这样 GID 就能自动添加到使用 PersistentVolume 的任何 Pod 中。
428450

429451
使用 `pv.beta.kubernetes.io/gid` 注解的方法如下所示:
430-
431452
```yaml
453+
apiVersion: v1
432454
kind: PersistentVolume
433455
apiVersion: v1
434456
metadata:
@@ -439,10 +461,10 @@ metadata:
439461
440462
<!--
441463
When a Pod consumes a PersistentVolume that has a GID annotation, the annotated GID
442-
is applied to all Containers in the Pod in the same way that GIDs specified in the
464+
is applied to all containers in the Pod in the same way that GIDs specified in the
443465
Pod's security context are. Every GID, whether it originates from a PersistentVolume
444466
annotation or the Pod's specification, is applied to the first process run in
445-
each Container.
467+
each container.
446468
-->
447469
当 Pod 使用带有 GID 注解的 PersistentVolume 时,注解的 GID 会被应用于 Pod 中的所有容器,
448470
应用的方法与 Pod 的安全上下文中指定的 GID 相同。
@@ -476,5 +498,3 @@ PersistentVolume are not present on the Pod resource itself.
476498
* [PersistentVolumeSpec](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#persistentvolumespec-v1-core)
477499
* [PersistentVolumeClaim](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#persistentvolumeclaim-v1-core)
478500
* [PersistentVolumeClaimSpec](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#persistentvolumeclaimspec-v1-core)
479-
480-

0 commit comments

Comments
 (0)