diff --git a/content/zh-cn/docs/tasks/configure-pod-container/configure-persistent-volume-storage.md b/content/zh-cn/docs/tasks/configure-pod-container/configure-persistent-volume-storage.md index a3ba703b09..5f58596b59 100644 --- a/content/zh-cn/docs/tasks/configure-pod-container/configure-persistent-volume-storage.md +++ b/content/zh-cn/docs/tasks/configure-pod-container/configure-persistent-volume-storage.md @@ -13,7 +13,7 @@ weight: 60 -本文介绍如何配置 Pod 使用 +本文将向你介绍如何配置 Pod 使用 {{< glossary_tooltip text="PersistentVolumeClaim" term_id="persistent-volume-claim" >}} 作为存储。 以下是该过程的总结: @@ -42,7 +42,8 @@ PersistentVolume. ## {{% heading "prerequisites" %}} -* 你需要一个包含单个节点的 Kubernetes 集群,并且必须配置 kubectl 命令行工具以便与集群交互。 +* 你需要一个包含单个节点的 Kubernetes 集群,并且必须配置 + {{< glossary_tooltip text="kubectl" term_id="kubectl" >}} 命令行工具以便与集群交互。 如果还没有单节点集群,可以使用 [Minikube](https://minikube.sigs.k8s.io/docs/) 创建一个。 . @@ -62,19 +64,19 @@ do not already have a single-node cluster, you can create one by using ## 在你的节点上创建一个 index.html 文件 -打开集群中节点的一个 Shell。 +打开集群中的某个节点的 Shell。 如何打开 Shell 取决于集群的设置。 例如,如果你正在使用 Minikube,那么可以通过输入 `minikube ssh` 来打开节点的 Shell。 -在 Shell 中,创建一个 `/mnt/data` 目录: +在该节点的 Shell 中,创建一个 `/mnt/data` 目录: -``` +```shell # 这里再次假定你的节点使用 "sudo" 来以超级用户角色执行命令 sudo sh -c "echo 'Hello from Kubernetes storage' > /mnt/data/index.html" ``` @@ -139,7 +141,7 @@ PersistentVolume uses a file or directory on the Node to emulate network-attache --> ## 创建 PersistentVolume -在本练习中,你将创建一个 *hostPath* 类型的 PersistentVolume。 +在本练习中,你将创建一个 **hostPath** 类型的 PersistentVolume。 Kubernetes 支持用于在单节点集群上开发和测试的 hostPath 类型的 PersistentVolume。 hostPath 类型的 PersistentVolume 使用节点上的文件或目录来模拟网络附加存储。 @@ -149,18 +151,36 @@ would provision a network resource like a Google Compute Engine persistent disk, an NFS share, or an Amazon Elastic Block Store volume. Cluster administrators can also use [StorageClasses](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#storageclass-v1-storage) to set up -[dynamic provisioning](https://kubernetes.io/blog/2016/10/dynamic-provisioning-and-storage-in-kubernetes). +[dynamic provisioning](/blog/2016/10/dynamic-provisioning-and-storage-in-kubernetes). Here is the configuration file for the hostPath PersistentVolume: --> 在生产集群中,你不会使用 hostPath。 集群管理员会提供网络存储资源,比如 Google Compute Engine 持久盘卷、NFS 共享卷或 Amazon Elastic Block Store 卷。 -集群管理员还可以使用 [StorageClasses](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#storageclass-v1-storage) 来设置[动态提供存储](https://kubernetes.io/blog/2016/10/dynamic-provisioning-and-storage-in-kubernetes)。 +集群管理员还可以使用 +[StorageClasses](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#storageclass-v1-storage) +来设置[动态提供存储](/blog/2016/10/dynamic-provisioning-and-storage-in-kubernetes)。 下面是 hostPath PersistentVolume 的配置文件: {{< codenew file="pods/storage/pv-volume.yaml" >}} + +配置文件指定卷位于集群节点上的 `/mnt/data` 路径。 +配置还指定了卷的容量大小为 10 GB, +访问模式为 `ReadWriteOnce`, +这意味着该卷可以被单个节点以读写方式安装。 +配置文件还在 PersistentVolume 中定义了 +[StorageClass 的名称](/zh-cn/docs/concepts/storage/persistent-volumes/#class) +为 `manual`。它将用于将 PersistentVolumeClaim 的请求绑定到此 PersistentVolume。 + @@ -216,7 +236,7 @@ Create the PersistentVolumeClaim: 创建 PersistentVolumeClaim: ```shell -kubectl create -f https://k8s.io/examples/pods/storage/pv-claim.yaml +kubectl apply -f https://k8s.io/examples/pods/storage/pv-claim.yaml ``` 查看 PersistentVolumeClaim: -``` +```shell kubectl get pvc task-pv-claim ``` @@ -299,7 +319,7 @@ kubectl apply -f https://k8s.io/examples/pods/storage/pv-pod.yaml ``` 检查 Pod 中的容器是否运行正常: @@ -308,7 +328,7 @@ kubectl get pod task-pv-pod ``` 打开一个 Shell 访问 Pod 中的容器: @@ -326,11 +346,11 @@ hostPath volume: # Be sure to run these 3 commands inside the root shell that comes from # running "kubectl exec" in the previous step --> -``` +```shell # 一定要在上一步 "kubectl exec" 所返回的 Shell 中执行下面三个命令 -root@task-pv-pod:/# apt-get update -root@task-pv-pod:/# apt-get install curl -root@task-pv-pod:/# curl localhost +apt update +apt install curl +curl http://localhost/ ``` ```shell # 这里假定你使用 "sudo" 来以超级用户的角色执行命令 @@ -390,7 +413,6 @@ You can now close the shell to your Node. - ## 在两个地方挂载相同的 persistentVolume {{< codenew file="pods/storage/pv-duplicate.yaml" >}} @@ -427,8 +449,8 @@ GID 不匹配或缺失将会导致无权访问错误。 这样 GID 就能自动添加到使用 PersistentVolume 的任何 Pod 中。 使用 `pv.beta.kubernetes.io/gid` 注解的方法如下所示: - ```yaml +apiVersion: v1 kind: PersistentVolume apiVersion: v1 metadata: @@ -439,10 +461,10 @@ metadata: 当 Pod 使用带有 GID 注解的 PersistentVolume 时,注解的 GID 会被应用于 Pod 中的所有容器, 应用的方法与 Pod 的安全上下文中指定的 GID 相同。 @@ -476,5 +498,3 @@ PersistentVolume are not present on the Pod resource itself. * [PersistentVolumeSpec](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#persistentvolumespec-v1-core) * [PersistentVolumeClaim](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#persistentvolumeclaim-v1-core) * [PersistentVolumeClaimSpec](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#persistentvolumeclaimspec-v1-core) - -