Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CronJob: unknown field "configMapRef"

I'm applying a Kubernetes CronJob. So far it works. Now I want to add the environment variables. (env: -name... see below) While tryng to apply I get the error

unknown field "configMapRef" in io.k8s.api.core.v1.EnvVarSource

I don't like to set all singles variables here. I prefer to link the configmap to not to double the variables. How is it possible set a link to the configmap.yaml variables in a CronJob file, how to code it?

Frank

apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: ad-sync
  creationTimestamp: 2019-02-15T09:10:20Z
  namespace: default
  selfLink: /apis/batch/v1beta1/namespaces/default/cronjobs/ad-sync
spec:
  concurrencyPolicy: Allow
  failedJobsHistoryLimit: 1
  successfulJobsHistoryLimit: 3
  suspend: false
  schedule: "0 */1 * * *"
  jobTemplate:
    metadata:
      labels:
        job: ad-sync
    spec:
      template:
        spec:
          containers:
          - name: ad-sync
            image: foo.azurecr.io/foobar/ad-sync
            command: ["dotnet", "AdSyncService.dll"]
            args: []
            env:
              - name: AdSyncService
                valueFrom:
                  configMapRef:
                    name: ad-sync-service-configmap
          restartPolicy: OnFailure
like image 670
Frank Mehlhop Avatar asked Dec 30 '25 04:12

Frank Mehlhop


2 Answers

There is no such field configMapRef in env field instead there is a field called configMapKeyRef

in order to get more detail about kubernetes objects, its convenient to use kubectl explain --help

for example if you would like to check all of the keys and their types you can use following command

kubectl explain cronJob --recursive

kubectl explain cronjob.spec.jobTemplate.spec.template.spec.containers.env.valueFrom.configMapKeyRef
like image 81
Suresh Vishnoi Avatar answered Dec 31 '25 17:12

Suresh Vishnoi


You should use configMapKeyRef for single value or configMapRef with envFrom

like image 24
Amityo Avatar answered Dec 31 '25 19:12

Amityo