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.
More on Write-a-Kubernetes-manifest tasks
Write a Deployment and Service for an Nginx app with 3 replicas, resources and probes.BeginnerAdd an HPA that scales the Deployment between 3 and 15 pods at 70% CPU.BeginnerFix this broken Deployment YAML.BeginnerWrite a ConfigMap and Secret and inject them as environment variables and as a mounted file.IntermediateWrite an Ingress that routes `/api` to the api service and `/` to the web service with TLS.IntermediateWrite a pod spec with a hardened securityContext.Intermediate