<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: ngx-dep3
  labels:
     app: ngx
     type: webservice
spec:
  replicas: 1
  selector:
    matchLabels:
      app: ngx
    template:
       metadata:
        labels:
          app: ngx
       spec:
        containers:
        - name: nginx
          image: nginx:1.8
</code></pre>
<p>kubectl apply -f ngx-dep.yaml</p>
<p>error: error validating &quot;ngx-dep.yaml&quot;: error validating data: [ValidationError(Deployment.spec.selector): unknown field &quot;template&quot; in io.k8s.apimachinery.pkg.apis.meta.v1.LabelSelector, ValidationError(Deployment.spec): missing required field &quot;template&quot; in io.k8s.api.apps.v1.DeploymentSpec]; if you choose to ignore these errors, turn validation off with --validate=false</p>

fenglming
<p>Change identation. <code>template</code> should be on the same level with  <code>replicas</code>, etc</p>
<pre><code>spec:
  replicas:
  selector:
  template:
</code></pre>
<p>Correct yaml:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: ngx-dep3
  labels:
     app: ngx
     type: webservice
spec:
  replicas: 1
  selector:
    matchLabels:
      app: ngx
  template:
     metadata:
      labels:
        app: ngx
     spec:
       containers:
         - name: nginx
           image: nginx:1.8

kubectl apply -f a.yaml
deployment.apps/ngx-dep3 created
</code></pre>
<p>For mere information and example please refer to <a href="https://v1-18.docs.kubernetes.io/docs/reference/generated/kubernetes-api/v1.18/#deployment-v1-apps" rel="nofollow noreferrer">Deployment v1 apps official docs</a></p>
