Kubernetes 无法访问与init容器共享的文件
我正在init容器中创建一个文件,并希望在主容器中使用该文件Kubernetes 无法访问与init容器共享的文件,kubernetes,google-kubernetes-engine,Kubernetes,Google Kubernetes Engine,我正在init容器中创建一个文件,并希望在主容器中使用该文件 containers: - name: test1 imagePullPolicy: Always image: newbusybox command: - "some command --from-file=tmp/file.txt" volumeMounts: - name: workdir mountPath: /tmp initCon
containers:
- name: test1
imagePullPolicy: Always
image: newbusybox
command:
- "some command --from-file=tmp/file.txt"
volumeMounts:
- name: workdir
mountPath: /tmp
initContainers:
- name: install
image: busybox
command: ["/bin/sh", "-c"]
args: ["echo test > /pod-data/file.txt]
volumeMounts:
- name: workdir
mountPath: /pod-data/
volumes:
- name: workdir
emptyDir: {}
Pods进入崩溃状态,出现以下错误
Error response from daemon: OCI runtime create failed: container_linux.go:349: starting container process caused "exec: \"some command --from-file=tmp/file.txt\": stat some comamnd --from-file=tmp/file.txt: no such file or directory": unknown
我已验证文件是否装载在tmp位置。我不确定您想要完成什么,但我需要同意user@Lauri Koskela提供的评论: 您可以尝试将命令字段更改为这样工作吗?错误消息表明错误不在文件共享中,而是在命令规范中 @Lauri Koskela发布的链接:
Pods
中的方法
此外,您在以下方面也有输入错误:
args:[“echo test>/pod data/file.txt]
#/working.txt&&sleep 3600” #-“cat/tmp/file.txt>/working.txt;sleep 3600” 体积数量: -姓名:workdir 挂载路径:/tmp 初始化容器: -名称:安装 图片:busybox 命令:[“/bin/sh”,“-c”] 参数:[“回声测试>/pod data/file.txt”] 体积数量: -姓名:workdir 挂载路径:/pod数据/ 卷数: -姓名:workdir emptyDir:{} 这个例子将:参数:[“echo test>/pod data/file.txt”]
- 使用
图像运行busybox
,并将“测试”文本保存到initContainer
目录中名为/pod data/
file.txt的文件中
- 运行main
并将container
先前创建的文件的内容现在位于cat
中,转换为/tmp
文件。它还将休眠3600秒working.txt
$kubectl exec-t busybox pod--cat/working.txt
您能否尝试将
字段更改为这样工作?错误消息表明错误不在文件共享中,而是在命令规范中。我认为您只是在开始时缺少了一个正斜杠(命令
而不是--from file=/tmp/file.txt
),好的,我也试过了。与--------------------------------------------------------------------------------------------相同的问题图像:“ubuntu:14.04”命令:-触摸tmp.txt------------------------------------------错误:无法启动容器“我的容器”:来自守护程序的错误响应:OCI运行时创建失败:container\u linux.go:349:启动容器进程导致“exec:\“touch tmp.txt\”:在$PATH中找不到可执行文件:请尝试在initContainer中使用->--from file=tmp/file.txt
。在主容器中:命令:[“bin/sh”]args:[“-c”,“echo hello>/pod data/hello.txt”]
command:[/bin/sh]args:[“-c”,“cat/tmp/hello.txt;sleep infinity”]
- 使用