Search code examples
kubernetesyamlnodeskubectlkubernetes-pod

Error validating Pod template with NodeSelector


    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.


Solution

  • 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: {}