Interview questions and model answers
"What is OPA and how does it work with Kubernetes?"
OPA is a general-purpose policy engine: it evaluates Rego policies against JSON input and returns a decision, while the caller enforces it. In Kubernetes, Gatekeeper registers OPA as a validating (and optionally mutating) admission webhook. The API server sends each matching create or update as an AdmissionReview; Gatekeeper evaluates the constraints and rejects violations with a message. Policies are ConstraintTemplates with Rego and Constraints that apply them with parameters and match rules, and an audit loop reports violations in existing resources.
"How would you introduce policies without breaking teams?"
Agree the rules and write helpful messages, deploy via GitOps, start constraints in dryrun or warn, use audit to find existing violations, work with owners to fix them with deadlines, then switch to deny gradually from dev to prod — with an exception process for genuine edge cases. I'd also run the same policies in CI with conftest so problems appear in PRs before deploy time.
"What happens if Gatekeeper is down?"
It depends on the webhook failure policy. Fail-open means requests are admitted and policies are bypassed during the outage; fail-closed means matching writes are rejected and deploys break. For fail-closed I'd run multiple replicas across AZs with a PDB, keep the timeout short, exempt system namespaces so the cluster can recover, and alert on webhook errors. Many teams choose fail-open plus audit as a compromise.
"OPA vs RBAC?"
RBAC answers whether an identity can perform an action on a resource type — for example, can this service account create Deployments in this namespace. It can't inspect content. OPA validates the object itself and context: registry, labels, security settings, resource limits. You need both.
"Gatekeeper or Kyverno?"
Kyverno uses Kubernetes-style YAML, supports validate, mutate, generate and image verification out of the box, and is quicker for a Kubernetes-focused team. Gatekeeper uses Rego, which is more expressive and reusable — the same language works in CI with conftest, in Envoy, and for Terraform. If a team is new to policies and only needs Kubernetes, I'd lean Kyverno; if we want one policy language across the platform or complex logic, OPA/Gatekeeper. I'd also use Pod Security Admission as a baseline and ValidatingAdmissionPolicy for simple CEL rules.
"Write a Rego rule that blocks images not from our ECR."
violation[{"msg": msg}] {
c := input.review.object.spec.containers[_]
not startswith(c.image, "123456789012.dkr.ecr.ap-south-1.amazonaws.com/")
msg := sprintf("image %v is not from the approved ECR registry", [c.image])
}
In practice I'd parameterise the allowed prefixes and also check initContainers and ephemeralContainers, or use the library's K8sAllowedRepos template.
"How do you test policies?"
Unit tests in Rego with opa test (positive and negative cases, coverage), gator verify suites for Gatekeeper templates and constraints, evaluating sample inputs with opa eval when debugging, and a dryrun period in a real cluster where audit shows what would be blocked. All of it runs in CI on the policy repo before Flux rolls policies to clusters.