kubernetes - Kubernetes 持久卷
问题描述
任何人都可以澄清 Kubernetes 中的持久卷吗?
在下面的示例中,/my-test-project 位于持久卷中。那么,为什么我需要这些挂载,因为从技术上讲,我的整个目录 /my-test-project 是持久的?如果保留整个目录,这些挂载路径和子路径将如何提供帮助。谢谢!
volumeMounts:
- name: empty-dir-volume
mountPath: /my-test-project/data-cache
subPath: data-cache
- name: empty-dir-volume
mountPath: /my-test-project/user-cache
subPath: user-cache
volumes:
- name: empty-dir-volume
emptyDir: {}
解决方案
您的/my-test-project
整个目录不会被持久化。
/my-test-project/data-cache
主机中的mountPath 或路径保留empty-dir-volume
在路径中data-cache
mountPath 保留
/my-test-project/user-cache
在empty-dir-volume
路径中user-cache
这意味着当您/my-test-project/data-cache
在data-cache
. 对于用户缓存也是如此。每当您在其中创建文件时,/my-test-project/
它都不会被持久化。假设您创建/my-test-project/new-dir
,现在new-dir
不会被持久化。
为了更好地解释,让我们看下面的例子(两个容器共享卷,但在不同的 mounthPath中):
apiVersion: v1
kind: Pod
metadata:
name: share-empty-dir
spec:
containers:
- name: container-1
image: alpine
command:
- "bin/sh"
- "-c"
- "sleep 10000"
volumeMounts:
- name: empty-dir-volume
mountPath: /my-test-project/data-cache
subPath: data-cache-subpath
- name: empty-dir-volume
mountPath: /my-test-project/user-cache
subPath: user-cache-subpath
- name: container-2
image: alpine
command:
- "bin/sh"
- "-c"
- "sleep 10000"
volumeMounts:
- name: empty-dir-volume
mountPath: /tmp/container-2
volumes:
- name: empty-dir-volume
emptyDir: {}
在容器 1 中:
- mountPath 保留
/my-test-project/user-cache
在empty-dir-volume
路径中user-cache-subpath
- mountPath 保留
/my-test-project/data-cache
在empty-dir-volume
路径中data-cache-subpath
在容器 2 中:
- mountPath
/tmp/container-2
保存empty-dir-volume
在路径“”中(表示“/”)
观察:
- 触摸
/my-test-project/user-cache/a.txt
。我们可以在 container-2 中看到这个文件,/tmp/container-2/user-cache-subpath/a.txt
并且反向将起作用 - 触摸
/my-test-project/data-cache/b.txt
。我们可以在 container-2 中看到这个文件,/tmp/container-2/data-cache-subpath/a.txt
并且反向将起作用 - touch
/tmp/container-2/new.txt
,我们永远不能将 container-1 中的这个文件作为我们在 container-1 中指定子路径的基本路径 - 类似地玩耍以获得更好的理解
注意:为了清楚起见,您使用的是emptyDir
volume 类型,这意味着每当 pod 被删除时,数据都会丢失。此类型仅用于在容器之间共享数据。
推荐阅读
- javascript - 如果子 p 标签为空,则隐藏 div 块
- android - HERE 映射 android 高级 Map.Projection 问题?
- javascript - React 复选框未将其状态设置为在标签单击时选中
- security - Kubernetes 身份验证和授权,如 Openshift
- ionic3 - 如何使用重叠的 ionic-col 或任何其他 div 禁用离子列
- python - SQL 错误 SELECT 语句返回整个表
- sql - 如何在SQL中的insert in语句中添加带有(')的字符串
- android - ViewStub 没有获得高程
- spring-boot - @CrossOrigin 注解 http.csrf().disable() 有什么区别?
- javascript - 如何为点击的类着色?