Kubernetes OPA Gatekeeper
The original author of this page is Guillaume
Definition
Open Policy Agent (OPA) Gatekeeper is a tool used to enforce admission policies in Kubernetes. These policies are defined using Rego, a policy language provided by OPA. Below is a basic example of a policy definition using OPA Gatekeeper:
This Rego policy checks if certain labels are present on Kubernetes resources. If the required labels are missing, it returns a violation message. This policy can be used to ensure that all resources deployed in the cluster have specific labels.
Apply Constraint
To use this policy with OPA Gatekeeper, you would define a ConstraintTemplate and a Constraint in Kubernetes:
In this YAML example, we define a ConstraintTemplate to require labels. Then, we name this constraint ensure-pod-has-label
, which references the k8srequiredlabels
ConstraintTemplate and specifies the required labels.
When Gatekeeper is deployed in the Kubernetes cluster, it will enforce this policy, preventing the creation of pods that do not have the specified labels.
References
Last updated