Latest
Kubernetes 1 min read

How Kubernetes Handles a kubectl Request

How Kubernetes Handles a kubectl Request
Kubernetes · November 28, 2026

Version note: examples use the Kubernetes v1.35 documentation snapshot, not necessarily the newest release. Check current support and component compatibility. These commands were not tested on a live cluster.

What this guide covers

The API server receives commands from kubectl. It checks who you are, whether you have permission, and whether the request meets cluster policy before storing an accepted change. Other components then act on that change.

Before you start

Use a test cluster and an administrator account for this exercise. Impersonation with --as requires permission; it is not a way to bypass access controls. Create the namespace with kubectl create namespace api-lab.

Step 1: Create a limited account

Save this as access.yaml and apply it with kubectl apply -f access.yaml:

apiVersion: v1
kind: ServiceAccount
metadata:
  name: observer
  namespace: api-lab
automountServiceAccountToken: false
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: pod-observer
  namespace: api-lab
rules:
  - apiGroups: [""]
    resources: ["pods"]
    verbs: ["get", "list", "watch"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: observer-pods
  namespace: api-lab
subjects:
  - kind: ServiceAccount
    name: observer
    namespace: api-lab
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: pod-observer

The ServiceAccount is an identity. The Role lists allowed actions in this namespace. The RoleBinding gives that Role to the account. Automatic token mounting is disabled because this exercise does not need a Pod token.

Step 2: Test the permissions

Run:

kubectl auth can-i list pods --namespace=api-lab \
  --as=system:serviceaccount:api-lab:observer
kubectl auth can-i get secrets --namespace=api-lab \
  --as=system:serviceaccount:api-lab:observer
kubectl get --raw='/readyz?verbose'
kubectl api-resources --api-group=apps

Listing Pods should be allowed; reading Secrets should not. A 401 response usually concerns authentication. A 403 response usually means the identified account lacks permission.

Step 3: Separate saving from running

A successful create or apply request means the API accepted the resource. It does not mean the scheduler placed a Pod or the container started. Check Pod conditions and events for those later stages.

Check the result

Confirm the account can perform only the intended actions. Avoid granting cluster-admin to fix a single missing permission. API readiness checks may themselves require administrative access.

References

PB
Written by

Parul Bedi

Notes and guides by Parul Bedi.

Up next

Install SonarQube on Ubuntu Step by Step

Sonar November 30, 2026 4 min read
Open post

Conversation

0 comments

No comments yet. Start the conversation below.

Leave a comment

Replying to a comment.
Be kind. Markdown is not supported in comments.