Error validating Pod template with NodeSelector

1/18/2019
    apiVersion: v1
    kind: Pod
    metadata:
      creationTimestamp: null
      labels:
        run: nginx4
      name: nginx4
    spec:
      containers:
      - image: nginx
        name: nginx4
      nodeSelector:
        app: "v1-tesla"
        resources: {}
      dnsPolicy: ClusterFirst
      restartPolicy: Never
    status: {}

When I run the above template kubectl create -f pod.yaml, I get the following error:

    error: error validating "podOnANode.yaml": error validating data: 
    ValidationError(Pod.spec.nodeSelector.resources): invalid type for 
    io.k8s.api.core.v1.PodSpec.nodeSelector: got "map", expected 
    "string"; if you choose to ignore these errors, turn validation off 
    with --validate=false

Any pointers to fix this would be great.

-- Avi
kubectl
kubernetes
kubernetes-pod
nodes
yaml

1 Answer

1/18/2019

The above error is for:

nodeSelector:
  app: "v1-tesla"
  resources: {}

Here, resources: {} representing map, but it should be string. So remove resources: {} or change it's value to string.

apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null
  labels:
    run: nginx4
  name: nginx4
spec:
  containers:
  - image: nginx
    name: nginx4
  nodeSelector:
    app: "v1-tesla"
    resources: "whatever"
  dnsPolicy: ClusterFirst
  restartPolicy: Never
status: {}
-- nightfury1204
Source: StackOverflow