How Gatekeeper Plugs Into Kubernetes
Gatekeeper doesn't run on your laptop or in your CI pipeline — it runs as a set of Pods inside the cluster itself. When you install Gatekeeper (via Helm or its manifest), it registers a ValidatingWebhookConfiguration object with the Kubernetes API Server. This is a built-in Kubernetes extension point that says: "Before finalizing any resource operation, call this URL first."
Here is the exact sequence of events when a developer runs kubectl apply -f bad-service.yaml:
- Request arrives: The
kubectlclient sends the YAML to the Kubernetes API Server over HTTPS. - Authentication & Authorization: The API Server checks who you are (authn) and whether you're allowed to create this resource type (authz via RBAC). Gatekeeper has not been involved yet.
- Admission phase begins: The API Server sees the registered webhook and pauses the request. It serializes the resource definition into a JSON payload called an AdmissionReview object and sends it to the Gatekeeper Pod via an internal HTTPS call.
- Policy evaluation: Gatekeeper receives the AdmissionReview, extracts the resource definition, and runs it against all active policies (written in Rego). This happens in milliseconds.
- Decision returned:
- Allow: Gatekeeper responds with
allowed: true. The API Server continues, writes the resource to etcd, and returns success to the developer. - Deny: Gatekeeper responds with
allowed: falseand a custom message (e.g., "Denied: LoadBalancers are prohibited in the dev namespace"). The API Server returns a403 Forbiddenerror to the developer. Nothing is written to etcd.
What Happens If Gatekeeper Is Down?
This is a critical operational question. The ValidatingWebhookConfiguration has a failurePolicy field. If set to Fail (the default for Gatekeeper), and the webhook is unreachable, the API Server will deny all requests — a safe but potentially disruptive default. If set to Ignore, requests bypass the webhook when it's unavailable. Gatekeeper runs multiple replicas and uses a leader-election pattern to ensure high availability, but understanding this failure mode is essential for production operations.
Interviewers frequently ask: "What happens to your cluster if Gatekeeper crashes?" The answer depends on failurePolicy. With failurePolicy: Fail, the cluster becomes read-only for creates/updates — nothing new can be deployed. With failurePolicy: Ignore, policies are silently bypassed. Production Gatekeeper deployments run 3+ replicas with pod disruption budgets to make this scenario extremely unlikely, but you must know the failure mode and have a runbook for it.