The terminal blinks. Access control is the difference between order and chaos in your Kubernetes cluster. Kubectl, the command-line tool for Kubernetes, can do more than deploy services—it can define who runs them, who stops them, and who never touches them.
Kubectl User Management Basics
Kubectl itself does not store user accounts. Kubernetes uses authentication and authorization modules to manage users. To grant or limit access, you combine kubectl commands with Kubernetes RBAC (Role-Based Access Control).
Create Users
Users in Kubernetes are often managed by an external identity provider, client certificates, or service accounts. For local clusters, you can create user credentials with OpenSSL and bind them via kubeconfig:
# Generate a key
openssl genrsa -out username.key 2048
# Create CSR
openssl req -new -key username.key -out username.csr -subj "/CN=username/O=groupname"
# Sign certificate
openssl x509 -req -in username.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out username.crt -days 365
Update your kubeconfig file with the new user entry, then use kubectl config use-context to switch and test.
Assign Roles and Permissions
RBAC defines what actions a user can take. Use Role or ClusterRole to define permissions, then bind resources to users. Example: