0
$ kubectl api-versions | grep batch
batch/v1
batch/v1beta1

当尝试创建这个具有单个容器和空卷的 CronJob 对象时,我收到此错误:

$ kubectl apply -f test.yaml
error: error parsing test.yaml: error converting YAML to JSON: yaml: line 19: did not find expected key

YAML

$ cat test.yaml
apiVersion: batch/v1beta1
  kind: CronJob
  metadata:
    name: dummy
  spec:
    schedule: "*/1 * * * *"
    jobTemplate:
      spec:
        template:
          spec:
            containers:
            - name: app
              image: alpine
              command: 
              - echo
              - Hello World!
              volumeMounts:
              - mountPath: /data
                name: foo
            restartPolicy: OnFailure
            volumes:
            - name: foo
              emptyDir: {}

根据我对API的阅读,我相信我的架构是合法的。任何想法或帮助将不胜感激。

4

1 回答 1

2

我认为是缩进问题。下面的 yaml 应该可以工作。

apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: dummy
spec:
  schedule: "*/1 * * * *"
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: app
            image: alpine
            command:
            - echo
            - Hello World!
            volumeMounts:
            - mountPath: /data
              name: foo
          restartPolicy: OnFailure
          volumes:
          - name: foo
            emptyDir: {}
于 2020-05-04T07:36:42.340 回答