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
But writes nothing to the file (I try to read it on the host after the run is completed but nothing happens)
What am i missing here?
Your job should like like this:
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
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
creates directory /data
, so this is why you found it.
I hope it helps.