<p>I've created a Kubernetes manifest file to create service account and roles. This is how it looks:</p>

<pre><code>apiVersion: v1
kind: ServiceAccount
metadata:
  name: test-service-account
  namespace: test
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: read-only-api
rules:
  - apiGroups:
      - ""
    resources: ["*"]
    verbs:
      - get
      - list
      - watch
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
  name: read-only-api
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: read-only-api
subjects:
  - kind: ServiceAccount
  name: test-service-account
  namespace: test
</code></pre>

<p>However, when I try to execute and apply the manifest, I get this error. I'm not sure if I'm having issues with indention or something else. </p>

<p><strong>error parsing service-account.yml: error converting YAML to JSON: yaml: line 10: did not find expected '-' indicator</strong></p>

<p>All help is greatly appreciated. I've tried indenting it back and forth, adding the '-' indicator to that specific line it's complaining about - but then I receive a new error message:</p>

<p><strong>error validating "service-account.yml": error validating data: ValidationError(ClusterRole.metadata): invalid type for io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta: got "array", expected "map"; if you choose to ignore these errors, turn validation off with --validate=false</strong></p>

<p>Thank you!</p>

Sk Snat
<p>service account yaml is fine</p>

<p>correct clusterrole and clusterrolebinding yaml as below</p>

<pre><code>apiVersion: v1
kind: ServiceAccount
metadata:
  name: test-service-account
  namespace: test
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: read-only-api
rules:
- apiGroups:
  - ""
  resources:
  - "*"
  verbs:
  - get
  - list
  - watch
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
  name: read-only-api
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: read-only-api
subjects:
- kind: ServiceAccount
  name: test-service-account
  namespace: test
</code></pre>

<pre><code>master $ kubectl create ns test
namespace/test created

serviceaccount/test-service-account created
clusterrole.rbac.authorization.k8s.io/read-only-api created
clusterrolebinding.rbac.authorization.k8s.io/read-only-api created
</code></pre>
