Hi, This is a very simple issue but it was very annoying while i was doing the l . . .

shubham mandhare:
Hi,
This is a very simple issue but it was very annoying while i was doing the lab. This is from the NodeAffinity lab. I was editing my deployment to add an affinity to it and i was doing this using vim . Every-time i tried to save the file it errored out giving the following error:

# deployments.apps "red" was not valid:
# * <nil>: Invalid value: "The edited file failed validation": [yaml: line 42: mapping values are not allowed in this context, invalid character 'a' looking for beginning of value]

This is k8’s complaining about the indentation the file. Vim is not too smart to indent the file by itself like VS Code. But i am pretty sure i had indented the file correctly:

    spec:
      containers:
      - image: nginx
        imagePullPolicy: Always
        name: nginx
        resources: {}
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
      affinity:
              nodeAffinity:
                                  requiredDuringSchedulingIgnoredDuringExecution
                        nodeSelectorTerms:
                                - matchExpressions:
                                        - key: <http://node-role.kubernetes.io/master|node-role.kubernetes.io/master>
                                          operator: Exists

It is complaining about indenting the word affinity which looks correctly indented to me. Is there a way to avoid this from happening?

unnivkn:

unnivkn:
compare with this code

Bryan Tanoue:
Try deleting resources

Bryan Tanoue:
Also on my phone so I can’t see the formatting well

shubham mandhare:
I can try deleting resources, but the solution asks to edit the live deployment. My formatting is similar to the above code. affinity is at the same indentation level as containers .

unnivkn:
can you check this: k edit deployment my-deoly. Then in the vim editor ESC+: set list

unnivkn:
and see any TAB or junk character is present. if it is, delete it & save. And try again

unnivkn:
look at the line number where it is giving the error.