kyverno
by Helm
Kubernetes Native Policy Management
About this chart
kyverno
Kubernetes Native Policy Management
About
Kyverno is a Kubernetes Native Policy Management engine.
It allows you to:
- Manage policies as Kubernetes resources (no new language required.)
- Validate, mutate, and generate resource configurations.
- Select resources based on labels and wildcards.
- View policy enforcement as events.
- Scan existing resources for violations.
This chart bootstraps a Kyverno deployment on a Kubernetes cluster using the Helm package manager.
Access the complete user documentation and guides at: https://kyverno.io.
Installing the Chart
IMPORTANT IMPORTANT IMPORTANT IMPORTANT
This chart changed significantly between v2 and v3. If you are upgrading from v2, please read Migrating from v2 to v3 section.
Add the Kyverno Helm repository:
$ helm repo add kyverno https://kyverno.github.io/kyverno/
Create a namespace:
You can install Kyverno in any namespace. The examples use kyverno as the namespace.
$ kubectl create namespace kyverno
Install the Kyverno chart:
$ helm install kyverno --namespace kyverno kyverno/kyverno
The command deploys Kyverno on the Kubernetes cluster with default configuration. The installation guide lists the parameters that can be configured during installation.
The Kyverno ClusterRole/ClusterRoleBinding that manages webhook configurations must have the suffix :webhook. Ex., *:webhook or kyverno:webhook.
Other ClusterRole/ClusterRoleBinding names are configurable.
Notes on using ArgoCD:
When deploying this chart with ArgoCD you will need to enable Replace in the syncOptions, and you probably want to ignore diff in aggregated cluster roles.
You can do so by following instructions in these pages of ArgoCD documentation:
ArgoCD uses helm only for templating but applies the results with kubectl.
Unfortunately kubectl adds metadata that will cross the limit allowed by Kubernetes. Using Replace overcomes this limitation.
Another option is to use server side apply, this will be supported in ArgoCD v2.5.
Finally, we introduced new CRDs in 1.8 to manage resource-level reports. Those reports are associated with parent resources using an ownerReference object.
As a consequence, ArgoCD will show those reports in the UI, but as they are managed dynamically by Kyverno it can pollute your dashboard.
You can tell ArgoCD to ignore reports globally by adding them under the resource.exclusions stanza in the ArgoCD ConfigMap.
resource.exclusions: |
- apiGroups:
- kyverno.io
kinds:
- AdmissionReport
- BackgroundScanReport
- ClusterAdmissionReport
- ClusterBackgroundScanReport
clusters:
- '*'
Below is an example of ArgoCD Application manifest that should work with this chart.
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: kyverno
namespace: argocd
spec:
destination:
namespace: kyverno
server: https://kubernetes.default.svc
project: default
source:
chart: kyverno
repoURL: https://kyverno.github.io/kyverno
targetRevision: 2.6.0
syncPolicy:
automated:
prune: true
selfHeal: true
syncOptions:
- CreateNamespace=true
- Replace=true
Notes on using Azure Kubernetes Service (AKS):
AKS contains a component known as Admission Enforcer which will attempt to modify Kyverno's webhooks if not excluded explicitly during Helm installation. If Admissions Enforcer is not disabled, this can lead to several symptoms such as high observed CPU usage and potentially cluster instability. Please see the Kyverno documentation here for more information and how to set this annotation on webhooks.
Migrating from v2 to v3
Direct upgrades from v2 of the Helm chart to v3 are not supported due to the number of breaking changes and manual intervention is required. Review and select an option after carefully reading below. Because either method requires down time, an upgrade should only be performed during a maintenance window. Regardless of the chosen option, please read all release notes very carefully to understand the full extent of changes brought by Kyverno 1.10. Release notes can be found at https://github.com/kyverno/kyverno/releases.
IMPORTANT NOTE: If you currently use clone-type generate rules with synchronization enabled, please do not upgrade to 1.10.0 as there is a bug which may prevent synchronization from occurring on all downstream (generated) resources when the source is updated. Please wait for a future patch where this should be resolved. See issue 7170 for further details.
Option 1 - Uninstallation and Reinstallation
The first option for upgrading, which is the recommended option, involves backing up Kyverno policy resources, uninstalling Kyverno, and reinstalling with v3 of the chart. Policy Reports for policies which have background mode enabled will be regenerated upon the next scan interval.
Pros
- Reduced complexity with minimal effort
- Allows re-checking older policies against new validation webhooks in 1.10
Cons
- Policy Reports which contained results only from admission mode and from policies/rules where background scans were disabled will be lost.
- Requires additional steps if data-type generate rules are used
Follow the procedure below.
- READ THE COMPLETE RELEASE NOTES FIRST
- Backup and export all Kyverno policy resources to a YAML manifest. Use the command
kubectl get pol,cpol,cleanpol,ccleanpol,polex -A -o yaml > kyvernobackup.yaml.- Before performing this step, if you use data-type generate rules with synchronization enabled (
generate.synchronize: true) disable synchronization first (setgenerate.synchronize: false). If you do not perform this step first, uninstallation of Kyverno in the subsequent step, which removes all policies, will result in deletion of generated resources.
- Before performing this step, if you use data-type generate rules with synchronization enabled (
- Uninstall your current version of Kyverno.
- Review the New Chart Values section and translate your desired features and configurations to the new format.
- Install the v3 chart with Kyverno 1.10.
- Restore your Kyverno policies. Use the command
kubectl create -f kyvernobackup.yaml.- Before performing this step, if step 2.1 applied to you, enable synchronization (set
generate.synchronize: true) AND add the fieldspec.generateExisting: true. This will cause existing, generated resources to be refreshed with the new labeling system used by Kyverno 1.10. Note that this may increment theresourceVersionfield on all downstream resources. Also, understand that when re-installing these policies withspec.generateExisting: true, it could result in additional resources being created at that moment based upon the current match defined in the policy. You may need to further refine the match/exclude blocks of your rules to account for this.
- Before performing this step, if step 2.1 applied to you, enable synchronization (set
Option 2 - Scale to Zero
In the second option, Kyverno policies do not have to be backed up however you perform more manual work in order to prepare for the upgrade to chart v3.
Pros
- Policy Reports which contained results from admission mode will be preserved
- Kyverno policies do not need to be backed up first
Cons
- Older policies will not be revalidated for correctness according to the breaking schema changes. Some policies may not work as they did before.
- Requires additional steps if data-type generate rules are used
Follow the procedure below.
- READ THE COMPLETE RELEASE NOTES FIRST
- Scale the
kyvernoDeployment to zero replicas. - If coming from 1.9 and you have installed the cleanup controller, scale the
kyverno-cleanup-controllerDeployment to zero replicas. - If step 3 applied to you, now delete the cleanup Deployment.
- Review the New Chart Values section and translate your desired features and configurations to the new format.
- Upgrade to the v3 chart by passing the mandatory flag
upgrade.fromV2=true. - If you use data-type generate rules with synchronization enabled (
generate.synchronize: true), after the upgrade modify those policies to add the fieldspec.generateExisting: true. This will cause existing, generated resources to be refreshed with the new labeling system used by Kyverno 1.10. Note that this may increment theresourceVersionfield on all downstream resources. Also, understand that when making this modification, it could result in additional resources being created at that moment based upon the current match defined in the policy. You may need to further refine the match/exclude blocks of your rules to account for this.
New Chart Values
In v3 chart values changed significantly, please read the instructions below to migrate your values:
config.metricsConfigis nowmetricsConfigresourceFiltersExcludeNamespaceshas been replaced withconfig.resourceFiltersExcludeNamespacesexcludeKyvernoNamespacehas been replaced withconfig.excludeKyvernoNamespaceconfig.existingConfighas been replaced withconfig.createandconfig.nameto support bring your own configconfig.existingMetricsConfighas been replaced withmetricsConfig.createandmetricsConfig.nameto support bring your own confignamespacehas been renamednamespaceOverrideinstallCRDshas been replaced withcrds.installtestImagehas been replaced withtest.imagetestResourceshas been replaced withtest.resourcestestSecurityContexthas been replaced withtest.securityContextreplicaCounthas been replaced withadmissionController.replicasupdateStrategyhas been replaced withadmissionController.updateStrategypriorityClassNamehas been replaced withadmissionController.priorityClassNamehostNetworkhas been replaced withadmissionController.hostNetworkdnsPolicyhas been replaced withadmissionController.dnsPolicynodeSelectorhas been replaced withadmissionController.nodeSelectortolerationshas been replaced withadmissionController.tolerationstopologySpreadConstraintshas been replaced withadmissionController.topologySpreadConstraintspodDisruptionBudgethas been replaced withadmissionController.podDisruptionBudgetantiAffinityhas been replaced withadmissionController.antiAffinityantiAffinity.enablehas been replaced withadmissionController.antiAffinity.enabledpodAntiAffinityhas been replaced withadmissionController.podAntiAffinitypodAffinityhas been replaced withadmissionController.podAffinitynodeAffinityhas been replaced withadmissionController.nodeAffinitystartupProbehas been replaced withadmissionController.startupProbelivenessProbehas been replaced withadmissionController.livenessProbereadinessProbehas been replaced withadmissionController.readinessProbecreateSelfSignedCerthas been replaced withadmissionController.createSelfSignedCertserviceMonitorhas been replaced withadmissionController.serviceMonitorpodSecurityContexthas been replaced withadmissionController.podSecurityContexttufRootMountPathhas been replaced withadmissionController.tufRootMountPathsigstoreVolumehas been replaced withadmissionController.sigstoreVolumeinitImagehas been replaced withadmissionController.initContainer.imageinitResourceshas been replaced withadmissionController.initContainer.resourcesimagehas been replaced withadmissionController.container.imageimage.pullSecretshas been replaced withadmissionController.imagePullSecretsresourceshas been replaced withadmissionController.container.resourcesservicehas been replaced withadmissionController.servicemetricsServicehas been replaced withadmissionController.metricsServiceinitContainer.extraArgshas been replaced withadmissionController.initContainer.extraArgsenvVarsInithas been replaced withadmissionController.initContainer.extraEnvVarsenvVarshas been replaced withadmissionController.container.extraEnvVarsextraArgshas been replaced withadmissionController.container.extraArgsextraInitContainershas been replaced withadmissionController.extraInitContainersextraContainershas been replaced withadmissionController.extraContainerspodLabelshas been replaced withadmissionController.podLabelspodAnnotationshas been replaced withadmissionController.podAnnotationssecurityContexthas been replaced withadmissionController.container.securityContextandadmissionController.initContainer.securityContextrbachas been replaced withadmissionController.rbacgeneratecontrollerExtraResourceshas been
Deploy kyverno with OpenTenant
Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has kyverno on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.
- Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
- Place the chartkyverno is pinned at v3.5.2 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
- ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below opentenant validate opentenant.yaml terraform init && terraform apply