Issue in deploying a pod on master node parsing issue

10/26/2020

I am testing to deploy two pods one on master and on one worker node for learning purpose.

I have the following yaml file to deploy a pod on a cluster on Master node.

apiVersion: v1 
kind: Pod
metadata:
name: edge-server
labels: 
    app: edge-server
spec:
 containers:
  - name:  tensor-keras
    image: tensor-keras:latest
    command: ["sleep"]
    args: ["infinity"]
    imagePullPolicy: Never
    ports:
    - containerPort: 31700
   nodeSelector:
       node_type: "kmaster" #also tried without quotes 

I have labelled the master node as node_type kmaster, I am retrieving the below error
"error parsing line 15 didnot find expected key"

Thank you very much for your help

-- abaair davis
docker
kubernetes
kubernetes-pod

3 Answers

10/26/2020

It may not like your indentation. It is kind of out of wack. You have multiple levels of indentation in one document. I see single, double, and 4-space indentation. YAML indentation is very important otherwise the wrong JSON is generated. Try this:

apiVersion: v1 
kind: Pod
metadata:
  name: edge-server
  labels: 
    app: edge-server
spec:
  containers:
    - name:  tensor-keras
      image: tensor-keras:latest
      command: ["sleep"]
      args: ["infinity"]
      imagePullPolicy: Never
      ports:
      - containerPort: 31700
  nodeSelector:
    node_type: kmaster
-- N-ate
Source: StackOverflow

10/26/2020

Try this, Verified it in http://www.yamllint.com/ also

apiVersion: v1 
kind: Pod
metadata:
name: edge-server
labels: 
    app: edge-server
spec:
    containers:
     - name:  tensor-keras
       image: tensor-keras:latest
       command: ["sleep"]
       args: ["infinity"]
       imagePullPolicy: Never
       ports:
        - containerPort: 31700
       nodeSelector:
          node_type: "kmaster"

enter image description here

-- Ashok
Source: StackOverflow

10/27/2020

nodeSelector should be at the same level as containers. We can use this K8s API reference to confirm the structure always.

apiVersion: v1 
kind: Pod
metadata:
name: edge-server
labels: 
  app: edge-server
spec:
    containers:
    - name:  tensor-keras
      image: tensor-keras:latest
      command: ["sleep"]
      args: ["infinity"]
      imagePullPolicy: Never
      ports:
      - containerPort: 31700
    nodeSelector:
      node_type: "kmaster" #also tried without quotes 
-- None-da
Source: StackOverflow