Kubernetes Manifest file won't convert from YML to JSON

8/21/2019

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

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

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.

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

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:

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

Thank you!

-- Sk Snat
docker
docker-for-mac
kubernetes

1 Answer

8/21/2019

service account yaml is fine

correct clusterrole and clusterrolebinding yaml as below

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
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
-- P Ekambaram
Source: StackOverflow