Sub topic 16
Operating policy webhooks: failure policy, availability and performance
This chapter assumes you know how admission webhooks work, and that you can write a Kyverno policy or a Gatekeeper Constraint. Here the focus is on keeping the policy engine from breaking your cluster.
The webhook is in the request path
Every matching create or update request waits for the webhook to answer. If the webhook is slow or down, the API server either rejects the request or lets it through. That choice is the failurePolicy field on the webhook configuration.
| Value | Behavior when the webhook is unreachable | Risk |
|---|---|---|
| `Fail` | The request is rejected | Outage can block deployments, and can block the engine's own Pods |
| `Ignore` | The request is admitted without checks | Policy is silently bypassed |
Neither value is safe for every case. Security-critical rules usually justify Fail. Convenience rules, such as adding labels, can use Ignore.
Where to set it
Gatekeeper exposes the behavior as a flag on its controller. Kyverno exposes it in its Helm values and per policy.
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: require-team-label
spec:
failurePolicy: Ignore
webhookTimeoutSeconds: 10
validationFailureAction: Audit
rules:
- name: check-team-label
match:
any:
- resources:
kinds:
- Pod
validate:
message: "The label 'team' is required."
pattern:
metadata:
labels:
team: "?*"webhookTimeoutSeconds caps how long the API server waits. The Kubernetes maximum is 30 seconds. Keep it low, because each slow call delays every matching request.
Availability
- Run at least three replicas of the admission controller, spread across nodes and zones, with a PodDisruptionBudget.
- Set resource requests so the controller is not evicted under node pressure.
- Exclude the engine's own namespace and
kube-systemfrom webhook matching. Otherwise aFailpolicy can block the controller from restarting, and the cluster cannot recover without manual edits.
Performance
- Narrow
matchrules to the kinds and operations you need. A policy that matches every resource sends far more traffic to the webhook. - Avoid API lookups inside policies on hot paths. In Kyverno,
apiCallandcontextlookups add latency. In Gatekeeper, replicating many resource kinds into OPA's cache costs memory. - Watch the engine's metrics: admission request latency, error counts, and webhook timeouts. Both engines expose Prometheus metrics.
Rollout practice
- Start new policies in audit mode (Kyverno
Audit, Gatekeeperdryrun). - Review the reports for false positives.
- Switch to enforcement for one namespace, then widen.
Exercise
A cluster runs one replica of its policy engine with failurePolicy: Fail and no namespace exclusions. A node failure takes that Pod down. Why can the cluster get stuck, and what two changes reduce the risk?
Show answer
The API server rejects the request to recreate the engine Pod, because the webhook it needs is the Pod that is missing. Run several replicas with a PodDisruptionBudget, and exclude the engine's namespace (and kube-system) from webhook matching. Choosing Ignore for non-critical policies also helps.