I'm trying to set node affinity using nodeSelector as discussed here: https://kubernetes.io/docs/user-guide/node-selection/
However, no matter if I use a Pod, a Replication Controller or a Deployment, I can't get the kubectl create to work properly. This is the error I get, and it happens with everything similarly:
Error from server (BadRequest): error when creating "test-pod.yaml": Pod in version "v1" cannot be handled as a Pod: [pos 222]: json: expect char '"' but got char 't'
Substitute "Deployment" or "ReplicationController" for "Pod" and it's the same error everywhere. Here is my yaml file for the test pod:
apiVersion: v1
kind: Pod
metadata:
name: nginx
labels:
env: test
spec:
containers:
- name: nginx
image: nginx
imagePullPolicy: IfNotPresent
nodeSelector:
ingress: yes
If I remove the nodeSelector part of the file, the pod builds successfully. This also works with Deployments and Replication Controllers as well. I made sure that the proper label was added to the node.
Any help would be appreciated!
In yaml, the token yes
evaluates to a boolean true
(http://yaml.org/type/bool.html)
Internally, kubectl
converts yaml to json as a preprocessing step. Your node selector is converting to "nodeSelector":{"ingress":true}
, which fails when trying to decode into a string-to-string map.
You can quote the string like this to force it to be treated as a string: ingress: "yes"