Published on

Kubernetes/Kubectl BadRequest Error for Number Configuration when defining an env variable

Authors

Today I was trying to deploy a yaml I had, but received the following:

> kubectl apply -f my-apps-deployment.yaml
Error from server (BadRequest): error when creating "my-apps-deployment.yaml": Pod in version "v1" cannot be handled as a Pod: v1.Pod: Spec: v1.PodSpec: Containers: []v1.Container: v1.Container: EnVar: Value: ReadString: expects " or n, but found 2, error found in #10 byte of ...|,"value":200}]...

My yaml looked similar to the below:

apiVersion: v1
kind: Pod
metadata:
  name: your-app
  labels:
    app: your-app
    component: cli
spec:
  containers:
  - name: some-image
    image: someimage:1.2.3
    imagePullPolicy: Always
    env:
    - name: COLUMNS
      value: 200
      ...

It turns out this issue was being caused by me using an integer 200 instead of a string "200". In general it seems it is better to specify numbers as strings otherwise this parsing error happens.

The fixed version of this yaml is below (note the quotes around 200):

apiVersion: v1
kind: Pod
metadata:
  name: your-app
  labels:
    app: your-app
    component: cli
spec:
  containers:
  - name: some-image
    image: someimage:1.2.3
    imagePullPolicy: Always
    env:
    - name: COLUMNS
      value: "200"
      ...