kyverno: [Bug] Possible memory leak in background controller
Kyverno Version
1.11.4
Description
My team and I recently upgraded kyverno from 1.9.3 (Helm version 2.7.3) to kyverno 1.11.4 (Helm version 3.1.4). Shortly after the upgrade we noticed OOMKills with the background controller. We bumped the memory from the default 128 MiB to 500 MiB and still experienced OOMKills. We then bumped the memory from 500 MiB to 5 GiB. The background controller started off at around 1 GiB of memory usage but over time has creeped up ~0.05 GiB every 15 minutes consistently for the past day and it hasn’t decreased at all like it has in the admission controller. We also noticed when we delete the pod the newly created pod’s memory restarts at ~1 GiB.
For some context about our cluster:
- EKS hosted with a Flux GitOps setup
- This cluster’s primary purpose is to host JupyterHub (multi-notebook Jupyter notebooks) https://github.com/jupyterhub/jupyterhub
- 5 kyverno policies enforced: 2 generate policies, 2 validate policies, and 1 mutate policy
- Our 2 generate policies automatically creates Gemini backups of the PersistentVolumeClaims backing JupyterHub notebooks
- ~160 pods and ~50 PVCs across 17 nodes
I followed https://kyverno.io/docs/troubleshooting/#kyverno-consumes-a-lot-of-resources-or-i-see-oomkills and our 5 kyverno policies seem reasonable to me. We don’t use wildcards. We also set the env variable GOGC=25 as suggested in other OOMKill related kyverno issues (https://github.com/kyverno/kyverno/issues/1540#issue-801267789 and https://github.com/kyverno/kyverno/issues/2524#issuecomment-941130204)
I’ll also mention our background controller is logging frequently with “start processing UR” log messages:
I0130 17:28:43.004385 1 generate.go:99] "start processing UR" logger="background" name="ur-dg7ph" policy="backup-restricted-jupyterhub-pvcs" resource="v1/PersistentVolumeClaim/jupyterhub-restricted/" ur="ur-dg7ph" resourceVersion="341004860"
I0130 17:28:43.202424 1 generate.go:99] "start processing UR" logger="background" name="ur-6rzfl" policy="backup-jupyterhub-pvcs" resource="v1/PersistentVolumeClaim/jupyterhub/" ur="ur-6rzfl" resourceVersion="341004864"
I0130 17:28:43.402158 1 generate.go:99] "start processing UR" logger="background" name="ur-7vkl2" policy="backup-jupyterhub-pvcs" resource="v1/PersistentVolumeClaim/jupyterhub/" ur="ur-7vkl2" resourceVersion="341004868"
I0130 17:28:43.554223 1 generate.go:99] "start processing UR" logger="background" name="ur-lrkkv" policy="backup-jupyterhub-pvcs" resource="v1/PersistentVolumeClaim/jupyterhub/" ur="ur-lrkkv" resourceVersion="341004870"
I0130 17:28:43.653491 1 generate.go:99] "start processing UR" logger="background" name="ur-w8fl6" policy="backup-jupyterhub-pvcs" resource="v1/PersistentVolumeClaim/jupyterhub/" ur="ur-w8fl6" resourceVersion="341004871"
I0130 17:28:44.301752 1 generate.go:99] "start processing UR" logger="background" name="ur-98bp6" policy="backup-jupyterhub-pvcs" resource="v1/PersistentVolumeClaim/jupyterhub/" ur="ur-98bp6" resourceVersion="341004874"
I0130 17:28:44.354023 1 generate.go:99] "start processing UR" logger="background" name="ur-8hppp" policy="backup-jupyterhub-pvcs" resource="v1/PersistentVolumeClaim/jupyterhub/" ur="ur-8hppp" resourceVersion="341004878"
I0130 17:28:44.451768 1 generate.go:99] "start processing UR" logger="background" name="ur-xdl9n" policy="backup-jupyterhub-pvcs" resource="v1/PersistentVolumeClaim/jupyterhub/" ur="ur-xdl9n" resourceVersion="341004885"
As of now we are working around this by ensuring the underlying node that has the background controller pod has a TTL of 2 days such that we don’t have a background controller pod that is older than 2 days.
Some questions:
- What would be next steps for troubleshooting this?
- Any other techniques for lowering the background controller’s memory consumption?
- I noticed the suggestion to disable admissionReports https://github.com/kyverno/kyverno/issues/5485#issuecomment-1329736903 and removing liveness and readiness probes https://github.com/kyverno/kyverno/issues/2524#issuecomment-941130204
- Could there be an underlying kyverno bug? Are there any other recently filed closely related issues?
- https://github.com/kyverno/kyverno/issues/9354 is kinda related but we are not experiencing memory spikes, our memory usage is slowly creeping up consistently
Thanks!
Slack discussion
CNCF Slack: https://cloud-native.slack.com/archives/C02CEARLA3D/p1706637340679879 Kubernetes Slack: https://kubernetes.slack.com/archives/CLGR9BJU9/p1706637306165739
Troubleshooting
- I have read and followed the documentation AND the troubleshooting guide.
- I have searched other issues in this repository and mine is not recorded.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 16 (6 by maintainers)
@chipzoller @realshuting
After clearing out the update requests and updating the policy our memory usage has decreased drastically to 3+ GiBs to a couple 100 MiBs.
I opened a PR in https://github.com/kyverno/website to udpate the OOM troubleshooting guide with the findings from this issue, most notably check pending requests and check clusterrole permissions. I hope this helps someone out in the future https://github.com/kyverno/website/pull/1138
Closing this PR since there is no memory leak
Let’s step back here. There should NOT be that many URs ever produced. This is the problem that needs to be addressed, not the memory usage which is a direct result of this.
First of all, let’s reduce the generate rules. You really only need one which can be applicable to both by adding in the match condition and using a variable in the Namespace field.
Next, match on CREATE operations only. I don’t see why this needs anything other than that.
If you’re able, please delete these generate rules and remove ALL UpdateRequests. You’ll have to do this anyway to make those changes.