Interview Prep/Real-World Interview/Write-a-Kubernetes-manifest tasks

Write RBAC that lets a CI service account deploy only in namespace `staging`.

IntermediateHands-onWrite-a-Kubernetes-manifest tasks
Answer
apiVersion: v1
kind: ServiceAccount
metadata: { name: ci-deployer, namespace: staging }
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata: { name: deployer, namespace: staging }
rules:
  - apiGroups: ["apps"]
    resources: ["deployments"]
    verbs: ["get", "list", "watch", "create", "update", "patch"]
  - apiGroups: [""]
    resources: ["services", "configmaps"]
    verbs: ["get", "list", "create", "update", "patch"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata: { name: ci-deployer, namespace: staging }
subjects:
  - kind: ServiceAccount
    name: ci-deployer
    namespace: staging
roleRef:
  kind: Role
  name: deployer
  apiGroup: rbac.authorization.k8s.io

Verify: kubectl auth can-i delete deployments -n staging --as=system:serviceaccount:staging:ci-deployer.

Key trick → A Role plus RoleBinding is namespace-scoped. Use a ClusterRole only when you need cluster-wide reach. Don't grant secrets access unless the pipeline really needs it.

All Real-World Interview questions Roadmap: Interview readiness

More on Write-a-Kubernetes-manifest tasks