Certainly! Here’s another example of a roleRef in a Role Binding that grants permissions to a specific Role within a namespace.
Example Role Definition
First, let's define a Role that allows reading and listing pods in a specific namespace:
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: pod-reader
namespace: my-namespace
rules:
- apiGroups: [""]
resources: ["pods"]
verbs: ["get", "list"]
Example Role Binding
Now, we can create a Role Binding that references this Role using roleRef:
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: pod-reader-binding
namespace: my-namespace
subjects:
- kind: User
name: alice
apiGroup: rbac.authorization.k8s.io
roleRef:
kind: Role
name: pod-reader
apiGroup: rbac.authorization.k8s.io
Explanation:
- Role: The
pod-readerRole allows the user togetandlistpods in themy-namespacenamespace. - Role Binding: The
pod-reader-bindingRole Binding grants the useralicethe permissions defined in thepod-readerRole. - roleRef: The
roleRefspecifies that this binding refers to thepod-readerRole, thus linking the user to the permissions defined in that Role.
This setup allows alice to read and list pods specifically in the my-namespace namespace.
