Namespaces, Labels & RBAC
Namespaces
Section titled “Namespaces”Folders for resources. Names only have to be unique within a namespace. Use them to separate teams, apps, or environments.
kubectl get nskubectl get pods -n demokubectl get pods -A # all namespaceskubectl config set-context --current --namespace=demo # stop typing -n demokubectl delete ns demo # deletes EVERYTHING insidePair with ResourceQuota (a namespace may use at most 10 CPUs) and NetworkPolicy (only pods labelled app=api may talk to the DB).
Labels & selectors
Section titled “Labels & selectors”Labels are key/value tags, and selectors query them. This loose coupling is how Deployments find their pods, Services find their endpoints, and you find things:
kubectl get pods -l app=demokubectl get pods -l 'env in (prod,staging)'RBAC: who can do what
Section titled “RBAC: who can do what”ServiceAccount / User ──(RoleBinding)──► Role: verbs [get, list, watch] on resources [pods]- Role / RoleBinding: within one namespace
- ClusterRole / ClusterRoleBinding: cluster-wide
- Every pod runs as a ServiceAccount. Give it the minimum permissions it needs (least privilege).
kubectl auth can-i delete pods -n demokubectl auth can-i --list --as=system:serviceaccount:demo:default -n demo