Course contentsShow
← Cloud and Infrastructure
Lesson 1413 of 2,98928. Kubernetes SecurityFree lesson

OPA Gatekeeper Architecture

Understanding Gatekeeper's architecture, CustomResourceDefinitions for policies, and how it extends OPA for Kubernetes admission control.

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

  1. Admins create a ConstraintTemplate with Rego logic (e.g., "container images must come from trusted registries")
  2. They instantiate Constraint resources from that template (e.g., "apply the trusted registry check to all Pods in production namespaces")
  3. Gatekeeper watches these CRDs, compiles the Rego policies, and loads them into its OPA engine
  4. 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.