kubernetes on minikube can't output to file

主宰稳场 提交于 2019-12-11 14:04:53

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/57372258/kubernetes-on-minikube-cant-output-to-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!