Interview Prep/Kubernetes/Control plane, RBAC, webhooks and autoscaling

A CI pipeline fails with `deployments.apps "api" is forbidden: User "system:serviceaccount:ci:deployer" cannot patch resource "deployments" in API group "apps" in the namespace "prod"`.

BeginnerTroubleshootingControl plane, RBAC, webhooks and autoscaling
Answer

Likely causes → The ServiceAccount has a Role in ci or staging but not in prod; or the binding's subjects[].namespace is wrong (a ServiceAccount subject must name the SA's own namespace, here ci).

Diagnose →

kubectl auth can-i patch deployments.apps -n prod --as system:serviceaccount:ci:deployer
kubectl get rolebinding -n prod -o yaml | yq '.items[] | select(.subjects[]?.name=="deployer")'

Fix →

apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata: {name: deployer, namespace: prod}
subjects:
  - {kind: ServiceAccount, name: deployer, namespace: ci}
roleRef: {kind: ClusterRole, name: app-deployer, apiGroup: rbac.authorization.k8s.io}

Prevent → Test pipeline permissions with kubectl auth can-i --list --as ... in a pre-flight step.

All Kubernetes questions Roadmap: Kubernetes networking, storage & scaling

More on Control plane, RBAC, webhooks and autoscaling