Skip to main content
In this tutorial, you’ll learn how to manage permissions in Kubernetes using RBAC. We’ll cover:
  1. Defining a Role
  2. Binding a Role to a User
  3. Inspecting Roles and RoleBindings
  4. Verifying Permissions with kubectl auth can-i
  5. Restricting Access to Specific Resource Names
Along the way, you’ll see code examples, handy tables, and useful callouts to help reinforce best practices.

1. Defining a Role in a Namespace

A Role grants a set of permissions within a single namespace. Each Role rule comprises: *Optional field to scope rules to named resources only. Example: create a Role named developer that can manage Pods and create ConfigMaps.
Save as 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.
Save as 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

Use kubectl 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:
To test in a different namespace:

5. Restricting Access to Specific Resource Names

Limit Role permissions to named resources using resourceNames:
Apply:

Watch Video

Practice Lab