Interview Prep/Kubernetes/Security, RBAC and policy

How do you stop privileged containers and hostPath mounts cluster-wide?

IntermediateScenarioSecurity, RBAC and policy
Answer

Situation read → A team tried to run a privileged pod in prod.

What I'd do →

  1. Use Pod Security Admission by labelling namespaces: kubectl label ns prod pod-security.kubernetes.io/enforce=restricted
  2. Roll out with warn and audit modes first
  3. For finer rules use Kyverno or OPA Gatekeeper
  4. Exempt only system namespaces
  5. Test with a dry run: kubectl label --dry-run=server --overwrite ns prod pod-security.kubernetes.io/enforce=baseline

Why → PSA gives three profiles (privileged, baseline, restricted) that replace PodSecurityPolicy.

Interview tip → Know that PSP was removed in 1.25.

All Kubernetes questions Roadmap: Kubernetes networking, storage & scaling

More on Security, RBAC and policy