Hi guys again, I am trying to edit a deployment yaml file using (kubectl edit de . . .

Amer Nureddin:
Hi guys again, I am trying to edit a deployment yaml file using (kubectl edit deployment xx) it opens the auto generated yaml file which is full of many fields etc…
now I am trying to add an affinity section but it throws this error:

deployments.apps “blue” was not valid:
# * <nil>: Invalid value: “The edited file failed validation”: [ValidationError(Deployment.spec.template.spec.affinity): unknown field “resources” in io.k8s.api.core.v1.Affinity, ValidationError(Deployment.spec.template.spec.affinity): unknown field “terminationMessagePath” in io.k8s.api.core.v1.Affinity, ValidationError(Deployment.spec.template.spec.affinity): unknown field “terminationMessagePolicy” in io.k8s.api.core.v1.Affinity]
#

when I edit, should I always clear the file and paste the simple version that we do normally? or it is ok to add on the autogenerated file and no need to clear it?

Tej_Singh_Rana:
Hello, @Amer Nureddin
Don’t needed to clear those fields. By default, its removed in v1.21 k8s version.

Mohit chauhan:
Giving error for erminationMessagePath … Sometime if you don’t use right indentation or use duplicate entries, you get errors. Try creating fresh Deploy file from yaml file which you created. it’ll work for sure. Use VB coder to correct yaml file.

I got similar error while adding nodeAffinity block by editing yaml file of an running deployment. The issue was the I was trying to add nodeAffinity block in spec of deployment file and not spec of container inside of template:
Hope this helps

Try deleting or hashing all the fields( resource type etc.) after adding the nodeaffinity details. It worked for me