I’m trying to set up a Cron Job in Kubernetes using a ConfigMap, and mount a shell script to a volume. I have valid YAML, but line 9 throws an error that it’s expecting a string:
apiVersion: v1
kind: ConfigMap
metadata:
name: elasticdump-configmap
namespace: default
data:
job.schedule: "*/5 * * * *"
spec:
restartPolicy: OnFailure
containers:
- name: elasticdump
image: elasticdump/elasticsearch-dump
imagePullPolicy: IfNotPresent
command: ["/bin/sh", "-c", "elasticdump.sh"]
volumeMounts:
- mountPath: /opt/data
name: blob01
resources:
requests:
memory: 1Gi
limits:
memory: 5Gi
volumes:
- name: blob01
persistentVolumeClaim:
claimName: pvc-blob
configMap:
name: elasticdump-configmap
items:
- key: elasticdump.sh
path: elasticdump.sh
I know I’m doing something wrong in the structure of the YAML, but I’m very new to Kubernetes, so would appreciate even a hint of what to do.
>Solution :
As it states in docs:
A ConfigMap is an API object that lets you store configuration for
other objects to use.
So, it’s not possible to define a CronJob such way. Please, look at special k8s Object called CronJob
apiVersion: batch/v1
kind: CronJob
metadata:
name: elasticdump-configmap
namespace: default
spec:
schedule: "*/5 * * * *"
jobTemplate:
spec:
template:
spec:
containers:
- name: elasticdump
image: elasticdump/elasticsearch-dump
imagePullPolicy: IfNotPresent
command: ["/bin/sh", "-c", "elasticdump.sh"]
volumeMounts:
- mountPath: /opt/data
name: blob01
resources:
requests:
memory: 1Gi
limits:
memory: 5Gi
volumes:
- name: blob01
persistentVolumeClaim:
claimName: pvc-blob
- name: elasticdump-configmap
configMap:
name: elasticdump-configmap
items:
- key: elasticdump.sh
path: elasticdump.sh
restartPolicy: OnFailure