Kyverno and CEL: Optimizing Admission Control in Kubernetes
Kubernetes admission control is crucial for enforcing policies and ensuring security in your cluster. However, it can become a performance bottleneck, particularly when multiple policies are evaluated for each admission request. Kyverno, a policy engine for Kubernetes, leverages Common Expression Language (CEL) to evaluate these policies. The challenge arises from the way Kyverno processes incoming AdmissionRequests, which can lead to redundant computations and increased latency.
When Kyverno receives an AdmissionRequest, it converts the raw JSON bytes into an unstructured map that CEL can understand. This conversion was previously done within a loop that iterated over each matched policy. In a typical scenario, such as creating a Pod with the Pod Security Standards set, around 16 policies might match. This means the same Pod was parsed 16 times, leading to unnecessary overhead. The recent optimization in Kyverno 1.19.2 moves this conversion outside the loop, allowing the engine to build the CEL request value once and reuse it for each policy. This change accounted for a staggering 86.8% of the allocation costs in the previous implementation, streamlining the evaluation process significantly.
In production, this optimization can lead to noticeable improvements in admission control performance. However, be cautious about the implementation details. The first attempt at optimization used a single shared builder for all CEL engines, which inadvertently altered policy behaviors. Always test your policies thoroughly after making changes. Remember to check the limitations section before quoting any performance metrics, as real-world scenarios may vary.
Key takeaways
- →Understand that CEL engines evaluate policies against a CEL activation, which is a set of variables your policy expressions can reference.
- →Recognize that moving the conversion of AdmissionRequests out of the policy evaluation loop can drastically reduce overhead.
- →Monitor the performance impact of policy evaluations, as the previous implementation led to 86.8% of allocation costs from redundant parsing.
- →Test your policies after optimization changes to avoid unintended behavior from shared builders.
- →Keep an eye on version updates, as significant performance improvements were introduced in Kyverno 1.19.2.
Why it matters
Optimizing admission control can lead to faster response times in your Kubernetes cluster, reducing latency during critical operations like Pod creation. This is essential for maintaining high availability and performance in production environments.
When NOT to use this
The official docs don't call out specific anti-patterns here. Use your judgment based on your scale and requirements.
Want the complete reference?
Read official docsIndustry-standard certifications built by the people behind Linux and Kubernetes. Earn the CKA — the gold standard Kubernetes administrator cert. OpsCanary readers get 30% off year-round with code OPSCANARY3.
Get CKA certified →Silos in Cloud Native Teams: Why Your Runtime Security Tool Isn't Enough
Autonomy in cloud native teams can lead to silos that undermine security. A baseline isn't just a policy; it's a testable set of answers tied to your workloads. Discover how to bridge the gap between autonomy and collaboration.
Harnessing OpenShell on Kubernetes: A Platform Engineer's Guide
OpenShell provides a safe runtime for agents on Kubernetes, solving critical isolation and security challenges. With its unique Agent Sandbox resource, you can manage workloads effectively while maintaining strict network policies.
AWS Nitro Sandboxes: Elevating Pod Security in EKS
AWS Nitro Sandboxes provide a powerful solution for workload isolation in Amazon EKS, giving each pod a hardware-enforced security boundary. This ensures that even if one pod is compromised, it cannot affect others or the host system.
Get the daily digest
One email. 5 articles. Every morning.
No spam. Unsubscribe anytime.