From c618e97a9ea368f330f81d7742845828ace49d6b Mon Sep 17 00:00:00 2001 From: wawa Date: Tue, 17 Mar 2020 21:44:23 +0800 Subject: [PATCH] Enhanced FileOrCreate description (#19465) --- content/zh/docs/concepts/storage/volumes.md | 33 +++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/content/zh/docs/concepts/storage/volumes.md b/content/zh/docs/concepts/storage/volumes.md index 6a46296cbb..797352e61b 100644 --- a/content/zh/docs/concepts/storage/volumes.md +++ b/content/zh/docs/concepts/storage/volumes.md @@ -988,6 +988,39 @@ spec: type: Directory ``` +{{< caution >}} + +应当注意,`FileOrCreate` 类型不会负责创建文件的父目录。如果挂载挂载文件的父目录不存在,pod 启动会失败。为了确保这种 `type` 能够工作,可以尝试把文件和它对应的目录分开挂载,如下所示: +{{< /caution >}} + +#### FileOrCreate pod 示例 + +```yaml +apiVersion: v1 +kind: Pod +metadata: + name: test-webserver +spec: + containers: + - name: test-webserver + image: k8s.gcr.io/test-webserver:latest + volumeMounts: + - mountPath: /var/local/aaa + name: mydir + - mountPath: /var/local/aaa/1.txt + name: myfile + volumes: + - name: mydir + hostPath: + # 确保文件所在目录成功创建。 + path: /var/local/aaa + type: DirectoryOrCreate + - name: myfile + hostPath: + path: /var/local/aaa/1.txt + type: FileOrCreate +``` + ### iscsi {#iscsi}