[ERROR: unknown field "spec.template.spec.nodeAffinity"]


(base) maye@maye-Inspiron-5547:~/github_repository/tensorflow_ecosystem/distribution_strategy$ kubectl apply -f maye_template.yaml 
service/dist-strat-example-worker-0 created
service/dist-strat-example-worker-1 created
replicationcontroller/dist-strat-example-worker-1 created
service/dist-strat-example-ps-0 created
replicationcontroller/dist-strat-example-ps-0 created
Error from server (BadRequest): error when creating "maye_template.yaml": ReplicationController in version "v1" cannot be handled as a ReplicationController: strict decoding error: unknown field "spec.template.spec.nodeAffinity"
(base) maye@maye-Inspiron-5547:~/github_repository/tensorflow_ecosystem/distribution_strategy$ 

(base) maye@maye-Inspiron-5547:~/github_repository/tensorflow_ecosystem/distribution_strategy$ kubectl apply -f maye_template.yaml 
service/dist-strat-example-worker-0 created
service/dist-strat-example-worker-1 created
replicationcontroller/dist-strat-example-worker-1 created
service/dist-strat-example-ps-0 created
replicationcontroller/dist-strat-example-ps-0 created
Error from server (BadRequest): error when creating "maye_template.yaml": Deployment in version "v1" cannot be handled as a Deployment: strict decoding error: unknown field "spec.selector.job", unknown field "spec.selector.name", unknown field "spec.selector.task", unknown field "spec.template.spec.nodeAffinity"
(base) maye@maye-Inspiron-5547:~/github_repository/tensorflow_ecosystem/distribution_strategy$ 

[SOLUTION]

This error is due to the resource has no the field, change the filed to the right one in yaml file.

---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: dist-strat-example-worker-0

  name: dist-strat-example-worker-0
  
spec:
  replicas: 1
  
  selector:
    matchLabels:
      app: dist-strat-example-worker-0

      
  template:
    metadata:
      labels:
        app: dist-strat-example-worker-0
    
    spec:
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: kubernetes.io/hostname
                operator: In
                values:
                - maye-inspiron-5547
                
(base) maye@maye-Inspiron-5547:~/github_repository/tensorflow_ecosystem/distribution_strategy$ kubectl apply -f maye_template.yaml
service/dist-strat-example-worker-0 created
deployment.apps/dist-strat-example-worker-0 created
service/dist-strat-example-worker-1 created
replicationcontroller/dist-strat-example-worker-1 created
service/dist-strat-example-ps-0 created
replicationcontroller/dist-strat-example-ps-0 created
(base) maye@maye-Inspiron-5547:~/github_repository/tensorflow_ecosystem/distribution_strategy$