Course contentsShow
← Cloud and Infrastructure
Lesson 1380 of 2,98928. Kubernetes SecurityFree lesson

Creating a Basic Role

Create a namespace-scoped Role that grants read access to pods.

Creating a Basic Role

What You'll Learn

You'll learn how to define a namespace-scoped Role that grants specific read permissions to pods within a Kubernetes namespace.

Understanding Basic Roles

A Role in Kubernetes is like a permission slip that defines what actions can be performed on which resources. Unlike ClusterRoles (which work across the entire cluster), a Role only applies within a single namespace—making it perfect for isolating permissions by project or team.

Think of it like giving someone keys to a specific floor of a building rather than master keys to the entire building.

Creating a Simple Role

To create a basic Role that grants read access to pods, you'll define:

  1. The namespace where the Role applies
  2. The resources you want to control (e.g., pods)
  3. The verbs (actions) allowed (e.g., get, list, watch)

Here's what a basic Role looks like in YAML:

apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: pod-reader
  namespace: default
rules:
- apiGroups: [""]
  resources: ["pods"]
  verbs: ["get", "list", "watch"]

This Role, named pod-reader, allows anyone assigned to it to get individual pods, list all pods, and watch for pod changes—but only in the default namespace. The empty string "" for apiGroups refers to the core API group where pods live.

Why This Matters

Creating granular Roles is the foundation of least-privilege security. You're defining exactly what access is needed—nothing more, nothing less—and limiting that access to a specific namespace boundary.

Key Takeaway: A basic Role combines resources, verbs, and a namespace scope to create fine-grained, isolated permissions that form the building blocks of secure Kubernetes access control.