Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Kubernetes ConfigMap expets 'string' in valid YAML

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading