
- Create one or more GlobalContextEntry resources to declare the data Kyverno should cache and how to keep it updated.
- Reference the cache in policy rules using a
globalReferenceinside the policycontextblock. Policies then read from Kyverno’s in-memory cache instead of calling the API server on every evaluation.
- kubernetesResource — informer-based, real-time caching of all resources of a single kind.
- apiCall — polling-based caching for filtered Kubernetes API queries or external services.

kubernetesResource: informer-based, near-real-time cache
Use thekubernetesResource type when you need a complete, up-to-date cache of all objects of a single resource kind. Kyverno uses Kubernetes informers (the same mechanism used by controllers) so the cache is updated instantly on create, update, or delete. There is no polling interval and no staleness window.
Example — cache all Deployments in the fitness namespace:
namespace field, Kyverno will cache deployments from all namespaces (cluster-wide).
When to use kubernetesResource:
- You need an always-up-to-date complete list of a resource kind.
- You prefer event-driven updates without polling.
- You want minimal staleness for policy decisions.
apiCall: filtered Kubernetes queries or external APIs with refresh intervals
UseapiCall when you want to:
- Cache a filtered subset of Kubernetes resources (for example, only items with a certain label) to avoid storing thousands of irrelevant objects, or
- Cache data from an external service (HTTP/HTTPS) on a schedule.
apiCall with either a urlPath (Kubernetes API query) or a service block (external URL), and set refreshInterval to control polling frequency.
Example — cache only Deployments in the fitness namespace with app=blue, refreshed every 10 seconds:
refreshInterval. The cached data can be up to that interval old — a trade-off that typically yields large performance gains when full real-time fidelity isn’t required.

External services and CA bundles
When theservice block points to an internal HTTPS endpoint signed by a private Certificate Authority, include the CA certificate in the caBundle field so Kyverno can verify the service identity.
Example — call an internal HTTPS service every minute and include the CA bundle:
When using an internal HTTPS
service, include the caBundle only if the service uses a private CA. Public CA-signed certificates do not require caBundle.Choosing the right type — quick comparison
Reference cached data in policies
After you create a GlobalContextEntry, reference it from a policy’scontext block using globalReference. The name must exactly match the GlobalContextEntry metadata.name. Use a JMESPath expression to extract or transform the cached data for your policy.
Example policy — deny Pod creation unless at least one Deployment exists in the blue-deployments cache:
- The
deploymentCountcontext variable receives the numeric result of the JMESPathlength(@)expression. - The
validate.denycondition blocks Pod creation whendeploymentCountequals0.
The
name under globalReference must exactly match the GlobalContextEntry metadata.name. Use JMESPath to shape the cached payload for your policy logic.Summary
Direct, synchronous API calls inside policy evaluations do not scale well. Kyverno’s GlobalContextEntry provides a configurable, high-performance cache for both Kubernetes resources and external API data:- Use
kubernetesResourcefor informer-based, near-real-time caches of complete resource sets. - Use
apiCallfor filtered Kubernetes queries or external service data on a poll schedule.
context.globalReference in many policies for efficient, low-cost evaluations.

- Kyverno Global context and external data: https://kyverno.io/docs/
- JMESPath query language: https://jmespath.org/
- Kubernetes informers (controller pattern): https://kubernetes.io/docs/reference/using-api/api-concepts/#watch-operations