In this tutorial, you’ll learn how to manage permissions in Kubernetes using RBAC. We’ll cover:Documentation Index
Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
Use this file to discover all available pages before exploring further.
- Defining a Role
- Binding a Role to a User
- Inspecting Roles and RoleBindings
- Verifying Permissions with
kubectl auth can-i - Restricting Access to Specific Resource Names
1. Defining a Role in a Namespace
A Role grants a set of permissions within a single namespace. Each Role rule comprises:| Field | Description |
|---|---|
| apiGroups | API group of the resource (empty string "" for core group) |
| resources | Kubernetes resources (e.g., pods, configmaps) |
| verbs | Allowed actions (e.g., get, list, create, delete) |
| resourceNames* | Restrict operations to specific resource names |
role-developer.yaml and apply:
Roles are namespace-scoped by default. To apply this Role in another namespace, add
namespace: your-namespace under metadata:.2. Binding a Role to a User with RoleBinding
A RoleBinding associates one or more subjects (users, groups, or service accounts) with a Role.rolebinding-devuser.yaml and run:
Ensure your Role and RoleBinding share the same namespace unless you intend to bind across namespaces.
3. Inspecting Roles and RoleBindings
Usekubectl to list or describe your RBAC resources:
-
List all Roles in the current namespace
-
List all RoleBindings in the current namespace
-
Describe a specific Role to view its rules
Sample output:
-
Describe a RoleBinding to see bound subjects
Sample output:
4. Verifying Permissions with kubectl auth can-i
Check whether a user can perform specific actions:5. Restricting Access to Specific Resource Names
Limit Role permissions to named resources usingresourceNames: