<p>I'm using k8s 1.11.2 to build my service, the YAML file looks like this:</p>

<p><strong>Deployment</strong></p>

<pre><code>apiVersion: apps/v1beta2
kind: Deployment
metadata:
  name: nginx-test
  namespace: default
  labels:
  - type: test 
spec:
  replicas: 1
  selector:
    matchLabels:
    - type: test 
  template:
    metadata:
      labels:
      - type: test 
    spec:
      containers:
      - image: nginx:1.14
        name: filebeat
        ports:
        - containerPort: 80
</code></pre>

<p><strong>Service</strong></p>

<pre><code>apiVersion: v1
kind: Service
metadata:
    labels:
    - type:test
spec:
  type: ExternalName
  externalName: my.nginx.com
  externalIPs:
  - 192.168.125.123
  clusterIP: 10.240.20.1
  ports: 
  - port: 80
    name: tcp
  selector:
  - type: test
</code></pre>

<hr>

<p>and I get this error:</p>

<blockquote>
  <p>error validating data: [ValidationError(Service.metadata.labels):
  invalid type for
  io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta.labels: got "array",
  expected "map", ValidationError(Service.spec.selector): invalid type
  for io.k8s.api.core.v1.ServiceSpec.selector: got "array", expected
  "map"];</p>
</blockquote>

<p>I am sure the format of my YAML file is right, because I used the website <a href="http://www.yamllint.com/" rel="noreferrer">http://www.yamllint.com/</a> to validate it.</p>

<p>Why am I getting this error?</p>

<p><a href="http://www.yamllint.com/" rel="noreferrer">yamllint.com</a> is a dubious service because it does not tell us which YAML version it is checking against and which implementation it is using. Avoid it.</p>

<p>More importantly, while your input may be valid YAML, this does not mean that it is a valid input for kubernetes. YAML allows you to create any kind of structure, while kubernetes expects a certain structure from you. This is what the error is telling you:</p>

<blockquote>
  <p>got "array", expected "map"</p>
</blockquote>

<p>This means that at a place where kubernetes expects a <em>mapping</em> you provided an array (<em>sequence</em> in proper YAML terms). The error message also gives you the path where this problem occurs:</p>

<blockquote>
  <p>ValidationError(Service.metadata.labels):</p>
</blockquote>

<p>A quick check on metadata labels in kubernetes reveals <a href="https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/" rel="noreferrer">this documentation</a>, which states that labels need to be mappings, not arrays.</p>

<p>So in your input, the last line here is the culprit:</p>

<pre><code>metadata:
  name: nginx-test
  namespace: default
  labels:
  - type: test
</code></pre>

<p><code>-</code> is a YAML indicator for a sequence item, creating a sequence as value for the key <code>labels:</code>. Dropping it will make it a mapping instead:</p>

<pre><code>metadata:
  name: nginx-test
  namespace: default
  labels:
    type: test
</code></pre>
