Scaling Kyverno

Scaling considerations for a Kyverno installation.

Scaling Kyverno

Kyverno supports scaling in multiple dimensions, both vertical as well as horizontal. It is important to understand when to scale, how to scale, and what the effects of that scaling will have on its operation. See the sections below to understand these topics better.

Because Kyverno is an admission controller with many capabilities and due to the variability with respect to environment type, size, and composition of Kubernetes clusters, the amount of processing performed by Kyverno can vary greatly. Sizing a Kyverno installation based solely upon Node or Pod count is often not appropriate to accurately predict the amount of resources it will require.

For example, a large production cluster hosting 60,000 Pods yet with no Kyverno policies installed which match on Pod has no bearing on the resources required by Kyverno. Because webhooks are dynamically managed by Kyverno according to the policies installed in the cluster, no policies which match on Pod results in no information about Pods being sent by the API server to Kyverno and, therefore, reduced processing load.

However, any policies which match on a wildcard ("*") will result in Kyverno being forced to process every operation (CREATE, UPDATE, DELETE, and CONNECT) on every resource in the cluster. Even if the policy logic itself is simple, only a single, simple policy written in such a manner and installed in a large cluster can and will have significant impact on the resources required by Kyverno.

Vertical Scale

Vertical scaling refers to increasing the resources allocated to existing Pods, which amounts to resource requests and limits.

We recommend conducting tests in your own environment to determine real-world utilization in order to best set resource requests and limits, but as a best practice we also recommend not setting CPU limits.

Horizontal Scale

Horizontal scaling refers to increasing the number of replicas of a given controller. Kyverno supports multiple replicas for each of its controllers, but the effect of multiple replicas is handled differently according to the controller. See the high availability section for more details.

Scale Testing

The following table shows the resource consumption (memory and CPU) and latency as a result of increased virtual users and iterations defined in k6. k6 is an open-source load testing tool for performance testing. k6 has multiple executors, the most popular of which is the shared-iterations executor. This executor creates a number of concurrent connections called virtual users. The total number of iterations is then distributed among these virtual users.

The test was conducted where we installed Kyverno policies to enforce the Kubernetes pod security standards using 17 policies. Subsequently, we developed a compatible Pod test to measure how long Kyverno takes to admit the admission request. For more details on these tests, refer to the load testing documentation here.

Testing was performed using KinD on an Ubuntu 20.04 system with an AMD EPYC 7502P 32-core processor @ 2.5GHz (max 3.35GHz) and 256GB of RAM.

Admission Controller

replicas# policiesRule TypeModeSubjectVirtual Users/IterationsLatency (avg/p(90), unit: ms)Memory (max)CPU (max)
117ValidateEnforcePods100/1,00044.28 / 67.64104Mi563m
117ValidateEnforcePods200/5,00087.88 / 156.22115Mi3878m
117ValidateEnforcePods500/10,000200.45 / 506.65116Mi4733m
317ValidateEnforcePods100/1,00034.14 / 54.7672Mi235m
317ValidateEnforcePods200/5,00060 / 107.19109Mi1398m
317ValidateEnforcePods500/10,000142 / 285.18186Mi2186m

AdmissionReview Reference

API requests, operations, and activities which match corresponding Kyverno rules result in an AdmissionReview request getting sent to admission controllers like Kyverno. The number and frequency of these requests may vary greatly depending on the amount and type of activity in the cluster. The following table below is provided to give a sense of how many minimum AdmissionReview requests may result from common operations. These figures only refer to the minimum number and, in actuality, the final count will almost certainly be greater but varies depending on things like finalizers and other controllers in the cluster.

OperationResourceConfigARs
CREATEPod1
DELETEPod3
CREATEDeploymentreplicas=13
UPDATEDeploymentChange image8
DELETEDeploymentreplicas=17
CREATEDeploymentreplicas=24
UPDATEDeploymentChange image13
DELETEDeploymentreplicas=210
CREATEJobrestartPolicy=Never, backoffLimit=43
DELETEJob4
CREATECronJobschedule="*/1 * * * *"4 (3 per invocation)
DELETECronJobschedule="*/1 * * * *", 2 completed9
CREATEConfigMap1
EDITConfigMap1
DELETEConfigMap1

These figures were captured using K3d v5.4.9 on Kubernetes v1.26.2 and Kyverno 1.10.0-alpha.2 with a 3-replica admission controller. When testing against KinD, there may be one less DELETE AdmissionReview for Pod-related operations.


Last modified April 23, 2024 at 10:30 PM PST: Add 1.12 load testing data (#1217) (0ebb566)