Configure Kubernetes RBAC
✓Works with OpenClaudeYou are a Kubernetes security engineer. The user wants to configure Kubernetes RBAC (Role-Based Access Control) to restrict pod and resource access by creating roles, cluster roles, and bindings.
What to check first
- Run
kubectl auth can-i list pods --as=system:serviceaccount:default:defaultto verify current permissions - Run
kubectl get serviceaccounts -Ato see existing service accounts across namespaces - Run
kubectl get roles,rolebindings,clusterroles,clusterrolebindingsto audit existing RBAC configuration
Steps
- Create a namespace with
kubectl create namespace rbac-demoto isolate RBAC test environment - Create a service account with
kubectl create serviceaccount dev-user -n rbac-demothat will be bound to roles - Define a Role manifest specifying allowed verbs (get, list, create, delete) and resource types (pods, deployments, services)
- Apply the Role with
kubectl apply -f role.yamlto register it in the cluster - Create a RoleBinding manifest linking the Role to the service account using
subjectsandroleReffields - Apply the RoleBinding with
kubectl apply -f rolebinding.yamlto activate the role assignment - Test permissions with
kubectl auth can-i get pods --as=system:serviceaccount:rbac-demo:dev-user -n rbac-demoto verify access - For cluster-wide access, use ClusterRole and ClusterRoleBinding instead of Role and RoleBinding, specifying
kind: ClusterRolein the manifest
Code
---
# Namespace for isolation
apiVersion: v1
kind: Namespace
metadata:
name: rbac-demo
---
# Service Account for the developer user
apiVersion: v1
kind: ServiceAccount
metadata:
name: dev-user
namespace: rbac-demo
---
# Role with specific permissions for pod management
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: pod-reader
namespace: rbac-demo
rules:
- apiGroups: [""]
resources: ["pods"]
verbs: ["get", "list", "watch"]
- apiGroups: [""]
resources: ["pods/logs"]
verbs: ["get"]
- apiGroups: ["apps"]
resources: ["deployments"]
verbs: ["get", "list"]
---
# RoleBinding connecting Role to ServiceAccount
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: dev-user-pod-reader
namespace: rbac-demo
subjects:
- kind: ServiceAccount
name: dev-user
namespace: rbac-demo
roleRef:
kind: Role
name: pod-reader
apiGroup: rbac.authorization.k8s.io
---
# ClusterRole
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related Docker & Kubernetes Skills
Other Claude Code skills in the same category — free to download.
Dockerfile Generator
Generate optimized Dockerfile for any project
Docker Compose
Create docker-compose.yml for multi-service apps
K8s Deployment
Generate Kubernetes deployment manifests
K8s Service
Create Kubernetes service and ingress configs
Helm Chart
Create Helm chart for application
Docker Multistage
Optimize Docker builds with multi-stage builds
K8s ConfigMap
Create ConfigMaps and Secrets management
Docker Security
Audit and fix Dockerfile security issues
Want a Docker & Kubernetes skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.