I am trying to create multiple roles in Kubernetes in a single YAML file.
I am not sure if it possible.
This is what I tried:
cat > ~/tmp/Role.yaml <<EOF
kind: Role
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
namespace: default
name: testRole1
rules:
- apiGroups: ["", "extensions", "apps"]
resources: ["pods"]
verbs: ["get", "list"]
kind: Role
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
namespace: default
name: testRole2
rules:
- apiGroups: ["", "extensions", "apps"]
resources: ["pods"]
verbs: ["get"]
EOF
kubectl create -f ~/tmp/Role.yaml
It creates me only the latter - testRole2
.
Is it possible to do it in one YAML file or I need to create YAML file for each Role ?
I just received an answer from @liggitt.
Need to add a record separator between them (---
).
FYI
You can write the yaml using List object as follows.
apiVersion: v1
kind: List
items:
- kind: Role
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
namespace: default
name: testRole1
rules:
- apiGroups: ["", "extensions", "apps"]
resources: ["pods"]
verbs: ["get", "list"]
- kind: Role
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
namespace: default
name: testRole2
rules:
- apiGroups: ["", "extensions", "apps"]
resources: ["pods"]
verbs: ["get"]