Complete the code to create a Role that allows reading pods in a namespace.
apiVersion: rbac.authorization.k8s.io/v1 kind: Role metadata: namespace: default name: pod-reader rules: - apiGroups: [""] resources: ["pods"] verbs: ["[1]"]
The verb get allows reading pods, which is essential for viewing pod details without modifying them.
Complete the code to bind the Role 'pod-reader' to a user named 'alice'.
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: read-pods-binding
namespace: default
subjects:
- kind: User
name: [1]
apiGroup: rbac.authorization.k8s.io
roleRef:
kind: Role
name: pod-reader
apiGroup: rbac.authorization.k8s.ioThe user alice is the one to whom the Role is being assigned, allowing her to read pods.
Fix the error in the RoleBinding that incorrectly references a ClusterRole instead of a Role.
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: read-pods-binding
namespace: default
subjects:
- kind: User
name: alice
apiGroup: rbac.authorization.k8s.io
roleRef:
kind: [1]
name: pod-reader
apiGroup: rbac.authorization.k8s.ioThe RoleBinding must reference a Role (not a ClusterRole) when binding permissions within a namespace.
Fill both blanks to create a ClusterRole that allows listing and watching all pods across namespaces.
apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: name: pod-list-watch rules: - apiGroups: [""] resources: ["pods"] verbs: ["[1]", "[2]"]
The verbs list and watch allow seeing pods and tracking changes across all namespaces.
Fill all three blanks to create a RoleBinding that assigns the 'pod-list-watch' ClusterRole to a service account named 'monitor' in the 'monitoring' namespace.
apiVersion: rbac.authorization.k8s.io/v1 kind: RoleBinding metadata: name: monitor-pods namespace: monitoring subjects: - kind: [1] name: [2] namespace: monitoring apiGroup: rbac.authorization.k8s.io roleRef: kind: [3] name: pod-list-watch apiGroup: rbac.authorization.k8s.io
The subject kind is ServiceAccount, the name is monitor, and the roleRef kind is ClusterRole because the role is cluster-wide.