Day 23/40 - Kubernetes Role-Based Access Control (RBAC) ????
Eric Mwakazi
Software Developer| Docker & Kubernetes | Linux | Cloud & DevOps Enthusiast |
Today’s task dives deeper into Role-Based Access Control (RBAC) in Kubernetes, a critical feature for managing user permissions. We created and tested roles, granting limited access to users while ensuring secure resource control within our cluster.
?? Key Concepts
Role and RoleBinding
??? Step-by-Step Commands
openssl genrsa -out krishna.key 2048
openssl req -new -key krishna.key -out krishna.csr -subj "/CN=krishna"
kubectl config set-context krishna --cluster=<cluster-name> --user=krishna
kubectl config use-context krishna
kubectl auth can-i create pods
kubectl config use-context admin
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
namespace: default
name: pod-reader
rules:
- apiGroups: [""]
resources: ["pods"]
verbs: ["get", "watch", "list"]
kubectl apply -f pod-reader-role.yaml
领英推荐
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: read-pods
namespace: default
subjects:
- kind: User
name: krishna
apiGroup: rbac.authorization.k8s.io
roleRef:
kind: Role
name: pod-reader
apiGroup: rbac.authorization.k8s.io
kubectl apply -f rolebinding.yaml
kubectl auth can-i get pods --as krishna
?? Test Results and Observations
Creating a New Pod:
Listing Pods:
Creating a Deployment:
?? Key Takeaways
??? Video Reference
For a visual guide, check out the Day 23 video on Kubernetes RBAC:
?? Share Your Insights
Learning RBAC helps us build robust, secure Kubernetes environments. If you’re working on similar tasks or want to share insights, let’s connect! Tagging @Eric mwakazi, @PiyushSachdeva and @CloudOps Community to join the discussion.
#40daysofkubernetes #RBAC #Kubernetes #AccessControl #DevOps