How to add new Pod property in yaml in kubernetes

8/7/2017

I want to add new pod property in yaml file while creating pod in Kubernetes. By looking at old properties I did all required changes in the kubernetes source code but I still get below parsing error:

error: error validating "podbox.yml": error validating data: found invalid field newproperty for v1.Pod

Example Pod yaml file :

apiVersion: v1
kind: Pod
metadata:
  name: podbox
  namespace: default
spec:
  containers:
  - image: busybox
    command:
      - sleep
      - "3600"
    imagePullPolicy: IfNotPresent
    name: podbox
    resources:
      requests:
        memory: "64Mi"
        cpu: "250m"
      limits:
        memory: "128Mi"
        cpu: "1"
  restartPolicy: Always
  newproperty: false
`newproperty`

not getting parsed while creating Pod.

Is there any specific changes required?

-- Rajendra
kubernetes
yaml

3 Answers

8/7/2017

Just remove the line

newproperty: false

from your YAML and you should be fine.

-- puja
Source: StackOverflow

8/7/2017

You don't want to add new fields to kind: Pod, because then your Kubernetes code will be on a fork and your config will be non-portable.

If you are planning a contribution to submit to the code Kubernetes code, you should first join the appropriate SIG (sig-node or sig-apps for Pod changes) and get support for your proposed change. Someone there can point you to example PRs that you can follow to add a field.

If you just need to put some extra information in a Pod that you or your own programs can parse, then use an annotation.

If you want to create a new type in your Kubernetes cluster, use a Custom Resource.

-- Eric Tune
Source: StackOverflow

8/7/2017

As far as I know you should be declaring then inside data:

apiVersion: v1
kind: Pod
metadata:
  name: podbox
  namespace: default
data:
  newproperty: false

if you want an enviroment variable to be passed to the docker use this structure:

....
 containers:
  - name: name
    image: some_image
    env:
    - name: SOME_VAR
      value: "Hello from the kubernetes"
....
-- kimy82
Source: StackOverflow