kyverno

by Helm

Helm chartv3.5.2App v1.15.2

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.

  1. READ THE COMPLETE RELEASE NOTES FIRST
  2. 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.
    1. Before performing this step, if you use data-type generate rules with synchronization enabled (generate.synchronize: true) disable synchronization first (set generate.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.
  3. Uninstall your current version of Kyverno.
  4. Review the New Chart Values section and translate your desired features and configurations to the new format.
  5. Install the v3 chart with Kyverno 1.10.
  6. Restore your Kyverno policies. Use the command kubectl create -f kyvernobackup.yaml.
    1. Before performing this step, if step 2.1 applied to you, enable synchronization (set generate.synchronize: true) AND add the field spec.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 the resourceVersion field on all downstream resources. Also, understand that when re-installing these policies with spec.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.

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.

  1. READ THE COMPLETE RELEASE NOTES FIRST
  2. Scale the kyverno Deployment to zero replicas.
  3. If coming from 1.9 and you have installed the cleanup controller, scale the kyverno-cleanup-controller Deployment to zero replicas.
  4. If step 3 applied to you, now delete the cleanup Deployment.
  5. Review the New Chart Values section and translate your desired features and configurations to the new format.
  6. Upgrade to the v3 chart by passing the mandatory flag upgrade.fromV2=true.
  7. If you use data-type generate rules with synchronization enabled (generate.synchronize: true), after the upgrade modify those policies to add the field spec.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 the resourceVersion field 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.metricsConfig is now metricsConfig
  • resourceFiltersExcludeNamespaces has been replaced with config.resourceFiltersExcludeNamespaces
  • excludeKyvernoNamespace has been replaced with config.excludeKyvernoNamespace
  • config.existingConfig has been replaced with config.create and config.name to support bring your own config
  • config.existingMetricsConfig has been replaced with metricsConfig.create and metricsConfig.name to support bring your own config
  • namespace has been renamed namespaceOverride
  • installCRDs has been replaced with crds.install
  • testImage has been replaced with test.image
  • testResources has been replaced with test.resources
  • testSecurityContext has been replaced with test.securityContext
  • replicaCount has been replaced with admissionController.replicas
  • updateStrategy has been replaced with admissionController.updateStrategy
  • priorityClassName has been replaced with admissionController.priorityClassName
  • hostNetwork has been replaced with admissionController.hostNetwork
  • dnsPolicy has been replaced with admissionController.dnsPolicy
  • nodeSelector has been replaced with admissionController.nodeSelector
  • tolerations has been replaced with admissionController.tolerations
  • topologySpreadConstraints has been replaced with admissionController.topologySpreadConstraints
  • podDisruptionBudget has been replaced with admissionController.podDisruptionBudget
  • antiAffinity has been replaced with admissionController.antiAffinity
  • antiAffinity.enable has been replaced with admissionController.antiAffinity.enabled
  • podAntiAffinity has been replaced with admissionController.podAntiAffinity
  • podAffinity has been replaced with admissionController.podAffinity
  • nodeAffinity has been replaced with admissionController.nodeAffinity
  • startupProbe has been replaced with admissionController.startupProbe
  • livenessProbe has been replaced with admissionController.livenessProbe
  • readinessProbe has been replaced with admissionController.readinessProbe
  • createSelfSignedCert has been replaced with admissionController.createSelfSignedCert
  • serviceMonitor has been replaced with admissionController.serviceMonitor
  • podSecurityContext has been replaced with admissionController.podSecurityContext
  • tufRootMountPath has been replaced with admissionController.tufRootMountPath
  • sigstoreVolume has been replaced with admissionController.sigstoreVolume
  • initImage has been replaced with admissionController.initContainer.image
  • initResources has been replaced with admissionController.initContainer.resources
  • image has been replaced with admissionController.container.image
  • image.pullSecrets has been replaced with admissionController.imagePullSecrets
  • resources has been replaced with admissionController.container.resources
  • service has been replaced with admissionController.service
  • metricsService has been replaced with admissionController.metricsService
  • initContainer.extraArgs has been replaced with admissionController.initContainer.extraArgs
  • envVarsInit has been replaced with admissionController.initContainer.extraEnvVars
  • envVars has been replaced with admissionController.container.extraEnvVars
  • extraArgs has been replaced with admissionController.container.extraArgs
  • extraInitContainers has been replaced with admissionController.extraInitContainers
  • extraContainers has been replaced with admissionController.extraContainers
  • podLabels has been replaced with admissionController.podLabels
  • podAnnotations has been replaced with admissionController.podAnnotations
  • securityContext has been replaced with admissionController.container.securityContext and admissionController.initContainer.securityContext
  • rbac has been replaced with admissionController.rbac
  • generatecontrollerExtraResources has 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.

  1. Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
  2. Place the chartkyverno is pinned at v3.5.2 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
  3. 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