I wanted to set a name for ephemeral volumeClaimTemplate but it didn't work.
apiVersion: batch/v1
kind: CronJob
metadata:
name: test-job
spec:
schedule: "*/5 * * * *"
jobTemplate:
spec:
template:
spec:
containers:
- name: test
image: my-image:dev
imagePullPolicy: Always
command: ["tail", "-f", "/dev/null"]
volumeMounts:
- mountPath: "/export"
name: export-dir
volumes:
- name: export-dir
ephemeral:
volumeClaimTemplate:
metadata:
name: test-pvc
spec:
accessModes: [ "ReadWriteOnce" ]
storageClassName: "do-block-storage-wait"
resources:
requests:
storage: 100Gi
which produces these errors:
- spec.jobTemplate.spec.template.spec.volumes[0].ephemeral.volumeClaimTemplate.metadata.name: Forbidden: cannot be set
- spec.jobTemplate.spec.template.spec.containers[0].volumeMounts[0].name: Not found: "export-dir"
Name field in volumeClaimTemplate is not allowed,that is why it is showing “spec.jobTemplate.spec.template.spec.volumes[0].ephemeral.volumeClaimTemplate.metadata.name: Forbidden: cannot be set” error.
In your config file you have set the name explicitly which is forbidden, try removing it from the ephemeral section. It may help to resolve the issue.
Refer to this Ephemeral volumes doc for more information.