<p>I am trying create deployment using yaml file in <strong>kubernetes</strong> but facing this specific error:</p>
<p><strong>Error from server (BadRequest): error when creating &quot;.\deployment_test.yaml&quot;: Deployment in version &quot;v1&quot; cannot be handled as a Deployment: v1.Deployment.Spec: v1.DeploymentSpec.Template: v1.PodTemplateSpec.ObjectMeta: v1.ObjectMeta.Labels: ReadMapCB: expect { or n, but found &quot;, error found in #10 byte of ...|&quot;labels&quot;:&quot;test&quot;},&quot;sp|...</strong></p>
<p>My yaml file is as follows:</p>
<pre><code>kind: Deployment
metadata:
    labels:
      environment: test
    name: agentstubpod-deployment
spec:
  replicas: 3
  selector: 
    matchLabels: 
      enviroment: test
  minReadySeconds: 10
  strategy: 
    rollingUpdate: 
      maxSurge: 1
      maxUnavailable: 0
    type: RollingUpdate
  template: 
    metadata:
      labels: test
    spec: 
      containers:
      - name: agentstub
        image: some-repo:latest 
---
apiVersion: apps/v1
kind: Deployment
metadata:
    labels:
      environment: test
    name: proxystubpod-deployment
spec:
  replicas: 3
  selector: 
    matchLabels: 
      enviroment: test
  minReadySeconds: 10
  strategy: 
    rollingUpdate: 
      maxSurge: 1
      maxUnavailable: 0
    type: RollingUpdate
  template: 
    metadata:
      labels: test
    spec: 
      containers:
      - name: procyservice
        image: some-repo:latest
</code></pre>
<p>What is wrong with this syntax? I am having a really hard time making a deployment</p>

<p>There are some misconfigurations.</p>
<ol>
<li>apiVersion is missing in the first deployment</li>
<li>indentation below <code>metadata</code> is incorrect</li>
<li>You must include the <code>metadata.name</code> field</li>
<li><code>spec.selector.matchLabels</code> and <code>spec.template.metadata.labels</code> should be matched.</li>
</ol>
<p>Here is the corrected example:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    environment: test
    name: agentstubpod-deployment
  name: dep1
spec:
  replicas: 3
  selector:
    matchLabels:
      environment: test
  minReadySeconds: 10
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0
    type: RollingUpdate
  template:
    metadata:
      labels:
        environment: test
    spec:
      containers:
      - name: agentstub
        image: some-repo:latest

---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    environment: test
    name: proxystubpod-deployment
  name: dep2
spec:
  replicas: 3
  selector:
    matchLabels:
      environment: test
  minReadySeconds: 10
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0
    type: RollingUpdate
  template:
    metadata:
      labels:
        environment: test
    spec:
      containers:
      - name: procyservice
        image: some-repo:latest
</code></pre>
