Kubernetes not accepting new job definition

9/20/2018

I'm running jobs on EKS. After trying to start a job with invalid yaml, it doesn't seem to let go of the bad yaml and keeps giving me the same error message even after correcting the file.

  1. I successfully ran a job.
  2. I added an environment variable with a boolean value in the env section, which raised this error:
    • Error from server (BadRequest): error when creating "k8s/jobs/create_csv.yaml": Job in version "v1" cannot be handled as a Job: v1.Job: Spec: v1.JobSpec: Template: v1.PodTemplateSpec: Spec: v1.PodSpec: Containers: []v1.Container: v1.Container: Env: []v1.EnvVar: v1.EnvVar: Value: ReadString: expects " or n, but found t, error found in #10 byte of ...|,"value":true},{"nam|..., bigger context ...|oduction"},{"name":"RAILS_LOG_TO_STDOUT","value":true},{"name":"AWS_REGION","value":"us-east-1"},{"n|...
  3. I changed the value to be a string yes, but the error message continues to show the original, bad yaml.
  4. No jobs show up in kubectl get jobs --all-namespaces
    • So I don't know where this old yaml would be hiding.

I thought this might be because I didn't have imagePullPolicy set to Always, but it happens even if I run the kubectl command locally.

Below is my job definition file:

apiVersion: batch/v1
kind: Job
metadata:
  generateName: create-csv-
  labels:
    transformer: AR
spec:
  template:
    spec:
      containers:
      - name: create-csv
        image: my-image:latest
        imagePullPolicy: Always
        command: ["bin/rails",  "create_csv"]
        env:
          - name: RAILS_ENV
            value: production
          - name: RAILS_LOG_TO_STDOUT
            value: yes
          - name: AWS_REGION
            value: us-east-1
          - name: AWS_ACCESS_KEY_ID
            valueFrom:
              secretKeyRef:
                name: aws
                key: aws_access_key_id
          - name: AWS_SECRET_ACCESS_KEY
            valueFrom:
              secretKeyRef:
                name: aws
                key: aws_secret_access_key
      restartPolicy: OnFailure
  backoffLimit: 6
-- jstim
amazon-eks
kubernetes

2 Answers

9/20/2018

"yes" must be quoted in yaml or it gets treated as a keyword that means a boolean true

Try this:

value: "yes"
-- Jordan Liggitt
Source: StackOverflow

1/20/2020

Single quotes didn't work for me, but the below did:

value: "'true'"
-- Ziemek
Source: StackOverflow