OPA Gatekeeper Architecture
What you'll learn: How OPA Gatekeeper extends Open Policy Agent to enforce Kubernetes admission control through a specialized architecture and CustomResourceDefinitions.
Understanding Gatekeeper's Design
You've learned about OPA fundamentals and admission webhooks. Gatekeeper bridges these two worlds by packaging OPA as a Kubernetes-native admission controller. Think of it as a translator: OPA speaks Rego (policy language), Kubernetes speaks YAML resources—Gatekeeper makes them fluent in each other's language.
Core Architectural Components
Gatekeeper runs as a validating admission webhook in your cluster. When Kubernetes considers creating or updating a resource, it asks Gatekeeper: "Does this violate any policies?" Gatekeeper consults its OPA engine and responds with allow or deny.
The genius lies in CustomResourceDefinitions (CRDs) that make policy management Kubernetes-native:
ConstraintTemplate: Defines the structure and logic of a policy type using Rego. Like a reusable policy blueprint.Constraint: An instance of a template that applies specific parameters. This is where you say "enforce this rule on these resources."
How It Works Together
- Admins create a
ConstraintTemplatewith Rego logic (e.g., "container images must come from trusted registries") - They instantiate
Constraintresources from that template (e.g., "apply the trusted registry check to all Pods in production namespaces") - Gatekeeper watches these CRDs, compiles the Rego policies, and loads them into its OPA engine
- Every admission request flows through Gatekeeper's webhook, evaluated against all active constraints
This architecture separates policy definition (templates) from policy enforcement (constraints), enabling reusability and governance at scale.
Key Takeaway: OPA Gatekeeper extends OPA as a Kubernetes admission controller using ConstraintTemplate and Constraint CRDs to turn policy enforcement into declarative, native Kubernetes resources.