我的 Pod 中有两个容器:
COPY ./files /my-files命令。该图像位于我的 GitLab Docker 注册表中。我想将容器 A 中存储在 /my-files 内的数据共享到容器 B。我认为我需要创建一个volumevolumeMounts在此 pod 内和容器中创建一个(它不是持久数据) 。
不幸的是当我添加volumeMounts到容器 A时mountPath: /my-files,该目录已被清空,并且创建映像时没有添加任何文件。
我应该怎么做才能保留这些数据并与容器 B 共享。
这是我的 Deployment.yaml 文件的一部分:
containers:
- name: Container-A
image: "my-gitlab-registry/my-image-a-with-copied-files"
volumeMounts:
- name: shared-data
mountPath: /my-files
- name: Container-B
image: "some-public-image"
volumeMounts:
- name: shared-data
mountPath: /files-from-container-a
volumes:
- name: shared-data
emptyDir: {}
Run Code Online (Sandbox Code Playgroud)
一个丑陋的黑客,使用 init 容器,将数据复制到emptyDir 卷中,然后将卷挂载到第二个容器中。
initContainers:
- name: init-config-data-copy-wait
image: datacontainer
command:
- sh
- "-ce"
- |
set -ex
cp -r /src-data/* /dst-data/
ls /dst-data/
volumeMounts:
- mountPath: /dst-data
name: dst-data-volume
volumes:
- name: dst-data-volume
emptyDir: {}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2873 次 |
| 最近记录: |