kyverno

by joaquinito2051

Helm chartv2.6.5App v1.8.5

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

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 Kuberrnetes. 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

Uninstalling the Chart

To uninstall/delete the kyverno deployment:

$ helm delete -n kyverno kyverno

The command removes all the Kubernetes components associated with the chart and deletes the release.

Values

KeyTypeDefaultDescription
nameOverridestringnilOverride the name of the chart
fullnameOverridestringnilOverride the expanded name of the chart
namespacestringnilNamespace the chart deploys to
customLabelsobject{}Additional labels
rbac.createbooltrueCreate ClusterRoles, ClusterRoleBindings, and ServiceAccount
rbac.serviceAccount.createbooltrueCreate a ServiceAccount
rbac.serviceAccount.namestringnilThe ServiceAccount name
rbac.serviceAccount.annotationsobject{}Annotations for the ServiceAccount
image.registrystringnilImage registry
image.repositorystring"ghcr.io/kyverno/kyverno"Image repository
image.tagstringnilImage tag Defaults to appVersion in Chart.yaml if omitted
image.pullPolicystring"IfNotPresent"Image pull policy
image.pullSecretslist[]Image pull secrets
initImage.registrystringnilImage registry
initImage.repositorystring"ghcr.io/kyverno/kyvernopre"Image repository
initImage.tagstringnilImage tag If initImage.tag is missing, defaults to image.tag
initImage.pullPolicystringnilImage pull policy If initImage.pullPolicy is missing, defaults to image.pullPolicy
initContainer.extraArgslist["--loggingFormat=text"]Extra arguments to give to the kyvernopre binary.
testImage.registrystringnilImage registry
testImage.repositorystring"busybox"Image repository
testImage.tagstringnilImage tag Defaults to latest if omitted
testImage.pullPolicystringnilImage pull policy Defaults to image.pullPolicy if omitted
replicaCountintnilDesired number of pods
podLabelsobject{}Additional labels to add to each pod
podAnnotationsobject{}Additional annotations to add to each pod
podSecurityContextobject{}Security context for the pod
securityContextobject{"allowPrivilegeEscalation":false,"capabilities":{"drop":["ALL"]},"privileged":false,"readOnlyRootFilesystem":true,"runAsNonRoot":true,"seccompProfile":{"type":"RuntimeDefault"}}Security context for the containers
testSecurityContextobject{"allowPrivilegeEscalation":false,"capabilities":{"drop":["ALL"]},"privileged":false,"readOnlyRootFilesystem":true,"runAsGroup":65534,"runAsNonRoot":true,"runAsUser":65534,"seccompProfile":{"type":"RuntimeDefault"}}Security context for the test containers
priorityClassNamestring""Optional priority class to be used for kyverno pods
antiAffinity.enablebooltruePod antiAffinities toggle. Enabled by default but can be disabled if you want to schedule pods to the same node.
podAntiAffinityobjectSee values.yamlPod anti affinity constraints.
podAffinityobject{}Pod affinity constraints.
nodeAffinityobject{}Node affinity constraints.
podDisruptionBudget.minAvailableint1Configures the minimum available pods for kyverno disruptions. Cannot be used if maxUnavailable is set.
podDisruptionBudget.maxUnavailablestringnilConfigures the maximum unavailable pods for kyverno disruptions. Cannot be used if minAvailable is set.
nodeSelectorobject{}Node labels for pod assignment
tolerationslist[]List of node taints to tolerate
hostNetworkboolfalseChange hostNetwork to true when you want the kyverno's pod to share its host's network namespace. Useful for situations like when you end up dealing with a custom CNI over Amazon EKS. Update the dnsPolicy accordingly as well to suit the host network mode.
dnsPolicystring"ClusterFirst"dnsPolicy determines the manner in which DNS resolution happens in the cluster. In case of hostNetwork: true, usually, the dnsPolicy is suitable to be ClusterFirstWithHostNet. For further reference: https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/#pod-s-dns-policy.
envVarsInitobject{}Env variables for initContainers.
envVarsobject{}Env variables for containers.
extraArgslist["--autogenInternals=true","--loggingFormat=text"]Extra arguments to give to the binary.
extraInitContainerslist[]Array of extra init containers
extraContainerslist[]Array of extra containers to run alongside kyverno
imagePullSecretsobject{}Image pull secrets for image verify and imageData policies. This will define the --imagePullSecrets Kyverno argument.
resources.limitsobject{"memory":"384Mi"}Pod resource limits
resources.requestsobject{"cpu":"100m","memory":"128Mi"}Pod resource requests
initResources.limitsobject{"cpu":"100m","memory":"256Mi"}Pod resource limits
initResources.requestsobject{"cpu":"10m","memory":"64Mi"}Pod resource requests
testResources.limitsobject{"cpu":"100m","memory":"256Mi"}Pod resource limits
testResources.requestsobject{"cpu":"10m","memory":"64Mi"}Pod resource requests
startupProbeobjectSee values.yamlStartup probe. The block is directly forwarded into the deployment, so you can use whatever startupProbes configuration you want. ref: https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-probes/
livenessProbeobjectSee values.yamlLiveness probe. The block is directly forwarded into the deployment, so you can use whatever livenessProbe configuration you want. ref: https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-probes/
readinessProbeobjectSee values.yamlReadiness Probe. The block is directly forwarded into the deployment, so you can use whatever readinessProbe configuration you want. ref: https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-probes/
generatecontrollerExtraResourceslist[]Additional resources to be added to controller RBAC permissions.
excludeKyvernoNamespacebooltrueExclude Kyverno namespace Determines if default Kyverno namespace exclusion is enabled for webhooks and resourceFilters
resourceFiltersExcludeNamespaceslist[]resourceFilter namespace exclude Namespaces to exclude from the default resourceFilters
config.resourceFilterslistSee values.yamlResource types to be skipped by the Kyverno policy engine. Make sure to surround each entry in quotes so that it doesn't get parsed as a nested YAML list. These are joined together without spaces, run through tpl, and the result is set in the config map.
config.existingConfigstring""Name of an existing config map (ignores default/provided resourceFilters)
config.annotationsobject{}Additional annotations to add to the configmap
config.excludeGroupRolestringnilExclude group role
config.excludeUsernamestringnilExclude username
config.webhooksstringnilDefines the namespaceSelector in the webhook configurations. Note that it takes a list of namespaceSelector and/or objectSelector in the JSON format, and only the first element will be forwarded to the webhook configurations. The Kyverno namespace is excluded if excludeKyvernoNamespace is true (default)
config.generateSuccessEventsboolfalseGenerate success events.
config.metricsConfigobject{"annotations":{},"namespaces":{"exclude":[],"include":[]}}Metrics config.
config.metricsConfig.annotationsobject{}Additional annotations to add to the metricsconfigmap
updateStrategyobjectSee values.yamlDeployment update strategy. Ref: https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#strategy
service.portint443Service port.
service.typestring"ClusterIP"Service type.
service.nodePortstringnilService node port. Only used if service.type is NodePort.
service.annotationsobject{}Service annotations.
topologySpreadConstraintslist[]Topology spread constraints.
metricsService.createbooltrueCreate service.
metricsService.portint8000Service port. Kyverno's metrics server will be exposed at this port.
metricsService.typestring"ClusterIP"Service type.
metricsService.nodePortstringnilService node port. Only used if metricsService.type is NodePort.
metricsService.annotationsobject{}Service annotations.
serviceMonitor.enabledboolfalseCreate a ServiceMonitor to collect Prometheus metrics.
serviceMonitor.additionalLabelsstringnilAdditional labels
serviceMonitor.namespacestringnilOverride namespace (default is the same as kyverno)
serviceMonitor.intervalstring"30s"Interval to scrape metrics
serviceMonitor.scrapeTimeoutstring"25s"Timeout if metrics can't be retrieved in given time interval
serviceMonitor.secureboolfalseIs TLS required for endpoint
serviceMonitor.tlsConfigobject{}TLS Configuration for endpoint
createSelfSignedCertboolfalseKyverno requires a certificate key pair and corresponding certificate authority to properly register its webhooks. This can be done in one of 3 ways: 1) Use kube-controller-manager to generate a CA-signed certificate (preferred) 2) Provide your own CA and cert. In this case, you will need to create a certificate with a specific name and data structure. As long as you follow the naming scheme

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 v2.6.5 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