使用Kubernetes中的容器存储/共享数据



我已经将一个需要使用几个CSV(~2gb(的python项目进行了码头化。为了降低映像大小,我没有在构建中包含CSV,而是选择通过卷将容器外部目录中的数据提供给正在运行的容器。在本地,当运行docker时,我只能进行

docker run -v ~/local/path/:/container/path my-image:latest

这是可行的,但我不确定如何在Kubernetes中实现这一点。我一直在阅读文档,对卷类型的数量、实际CSV应该存储在哪里等感到困惑。

根据我提供的项目信息,有明显的解决方案吗?

如果你想从Docker复制这种行为,最常见的方法就是使用hostPath。类似这样的东西:

apiVersion: v1
kind: Pod
metadata:
name: test-pd
spec:
containers:
- image: my-image:latest
name: my-container
volumeMounts:
- mountPath: /container/path
name: test-volume
volumes:
- name: test-volume
hostPath:
path: /usr/local/path
type: Directory

这里是容器之间共享的一个典型示例。您可以将数据保存在一个单独的容器中,将代码保存在另一个容器中。

https://kubernetes.io/docs/tasks/access-application-cluster/communicate-containers-same-pod-shared-volume/

apiVersion: v1
kind: Pod
metadata:
name: two-containers
spec:
restartPolicy: Never
volumes:
- name: shared-data
emptyDir: {}
containers:
- name: nginx-container
image: nginx
volumeMounts:
- name: shared-data
mountPath: /usr/share/nginx/html
- name: debian-container
image: debian
volumeMounts:
- name: shared-data
mountPath: /pod-data
command: ["/bin/sh"]
args: ["-c", "echo Hello from the debian container > /pod-data/index.html"]

希望能有所帮助。

最新更新