Interview Prep/DevSecOps/Kubernetes Security

Write a policy that rejects any Deployment without CPU and memory limits and without a `team` label. Which tool and how?

IntermediateScenarioKubernetes Security
Answer

Situation read → An admission policy engine handles this. Kyverno writes it in YAML, Gatekeeper in Rego, or built-in ValidatingAdmissionPolicy in CEL.

What I'd do →

  1. Kyverno example:
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata: { name: require-limits-and-team }
spec:
  validationFailureAction: Audit
  rules:
  - name: check
    match: { any: [ { resources: { kinds: [Deployment] } } ] }
    validate:
      message: "team label and resource limits are required"
      pattern:
        metadata: { labels: { team: "?*" } }
        spec: { template: { spec: { containers: [ { resources: { limits: { cpu: "?*", memory: "?*" } } } ] } } }
  1. Start in Audit, review policy reports, then switch to Enforce.
  2. Run the same policies in CI with kyverno apply so developers see failures before merge.

Why → Limits prevent noisy-neighbour denial of service; labels give ownership for incidents.

Interview tip → "Audit first, then enforce, and test in CI too."

All DevSecOps questions Roadmap: Supply chain, secrets & identity

More on Kubernetes Security