minikube上的kubernetes无法输出到文件 [英] kubernetes on minikube can't output to file
问题描述
我在Ubuntu 18上使用minikube并运行一个kubernetes作业,该作业只需挂载dir并使用此yaml文件将某些内容输出到文件
I am using minikube on Ubuntu 18 and running a kubernetes job that should simply mount a dir and output something to a file using this yaml file
apiVersion: batch/v1
kind: Job
metadata:
name: pi13
spec:
template:
spec:
containers:
- name: pi
image: perl
command: ["/bin/echo"]
args: ["1 >> /data/text12.txt"]
volumeMounts:
- mountPath: /data
name: data
volumes:
- name: data
hostPath:
path: /home/user/data
restartPolicy: Never
backoffLimit: 1
它运行良好,并在仪表板中提供了此输出
It runs fine and gives this output in the dashboard
1 >>/data/shai12.txt
1 >> /data/shai12.txt
但是不向文件写入任何内容(运行完成后我尝试在主机上读取它,但是没有任何反应)
But writes nothing to the file (I try to read it on the host after the run is completed but nothing happens)
我在这里想念什么?
推荐答案
您的工作应该像这样:
apiVersion: batch/v1
kind: Job
metadata:
name: pi13
spec:
template:
spec:
containers:
- name: pi
image: perl
command: [ "sh", "-c"]
args: ["echo 1 >> /data/text12.txt"]
volumeMounts:
- mountPath: /data
name: data
volumes:
- name: data
hostPath:
path: /tmp/data
restartPolicy: Never
backoffLimit: 1
在您的情况下,您将整个1 >> /data/text12.txt
传递给echo命令,结果将显示1 >> /data/text12.txt
您可以在作业日志中检查的内容.
In your case you pass whole 1 >> /data/text12.txt
to echo command and as results it prints 1 >> /data/text12.txt
what you can check in job logs.
hostPath
创建目录/data
,所以这就是找到它的原因.
hostPath
creates directory /data
, so this is why you found it.
希望对您有帮助.
这篇关于minikube上的kubernetes无法输出到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!