kyverno-production-policies

by Oreon Information Technology

Helm chartv0.1.2App 0.1.0MITVerified publisher

The Kubernetes production-readiness checklist as Kyverno policies - requests and limits, probes, owner labels, no latest tags, PodDisruptionBudgets and spread for multi-replica workloads, no NodePorts, nothing in the default namespace. Audit mode by default, enforce per namespace.

About this chart

kyverno-production-policies

The Kubernetes production readiness checklist as Kyverno policies. Install it in Audit mode (the default) and you get a findings list for the whole cluster in a few minutes; move namespaces to Enforce when they are clean.

PolicyChecksDefault
require-requests-limitsCPU and memory requests and a memory limit on every container and init container (CPU limit optional)on
require-probesliveness and readiness probes on Deployments, StatefulSets, DaemonSets (startup probe optional)on
require-labelspods carry the labels you route cost and alerts by (app.kubernetes.io/name, team by default)on
disallow-latest-tagimages have an explicit tag or digest, and it is not lateston
require-pdbDeployments and StatefulSets with 2+ replicas have a PodDisruptionBudget whose selector matches their pod labelson
require-topology-spreadDeployments and StatefulSets with 2+ replicas declare topologySpreadConstraints or podAntiAffinityon
restrict-nodeportno NodePort serviceson
disallow-default-namespacenothing runs in defaulton
restrict-image-registriesimages only from the registries you listoff
require-ro-rootfsreadOnlyRootFilesystem: true on every containeroff

Pod-level checks are auto-generated by Kyverno for Deployments, StatefulSets, DaemonSets, Jobs and CronJobs, so reports point at the controller, not the pod. Pod Security Admission levels (privileged containers, host namespaces, root) are deliberately not duplicated here: set them as namespace labels, for example with our namespace-baseline chart.

Install

Needs Kyverno 1.13 or newer (rule-level failureAction).

helm repo add oreonit https://oreondev.github.io/helm-charts
helm install readiness oreonit/kyverno-production-policies -n kyverno

Read the findings:

kubectl get clusterpolicyreport,policyreport -A
kubectl get policyreport -A -o json \
  | jq -r '.items[] | .metadata.namespace as $ns | .results[]? | select(.result=="fail")
           | [$ns, .policy, .resources[0].kind, .resources[0].name] | @tsv' \
  | sort | uniq -c | sort -rn

Enforce in one namespace while the rest keeps auditing:

helm upgrade readiness oreonit/kyverno-production-policies -n kyverno --reuse-values \
  --set 'enforceNamespaces={staging}'

Enforce everywhere: --set failureAction=Enforce.

Values

KeyDefaultDescription
namePrefix""Prefix for ClusterPolicy names
failureActionAuditAudit or Enforce, for every policy
enforceNamespaces[]Namespaces that enforce regardless of failureAction
excludeNamespaceskube-*, kyverno, gmp-*, gke-*, calico-*, tigera-operatorNamespaces no policy looks at (wildcards allowed)
backgroundtrueScan existing resources, not only new requests
policies.<name>.enabledsee tableTurn individual policies on or off
policies.requireRequestsLimits.requireCpuLimitfalseAlso require CPU limits
policies.requireProbes.requireStartupProbefalseAlso require startup probes
policies.requireLabels.labelsapp.kubernetes.io/name, teamRequired pod labels
policies.requirePdb.minReplicas2Replica count from which a PDB is required
policies.requireTopologySpread.minReplicas2Replica count from which spreading is required
policies.restrictImageRegistries.registries[]Allowed image prefixes, e.g. ghcr.io/my-org/*
rbac.kyvernoReadPdbstrueAggregated ClusterRole so Kyverno can list PodDisruptionBudgets for require-pdb

Notes

  • require-pdb looks up PodDisruptionBudgets through the Kubernetes API (apiCall with Kyverno's label_match). The chart ships an aggregated ClusterRole for that; if your Kyverno installation does not use the rbac.kyverno.io/aggregate-to-* labels, grant the Kyverno controllers list on poddisruptionbudgets.policy yourself. Only matchLabels selectors are compared: a PDB that selects with matchExpressions alone is not seen, so give such PDBs a matchLabels entry or exclude the workload.
  • Audit findings for workloads that existed before the policy appear through background scans; give it a couple of minutes after install.
  • Exceptions: use Kyverno PolicyException resources for the one workload that genuinely needs a NodePort, rather than turning the policy off.
  • A clean report is a readiness checklist you can show an auditor. If you would like the rest of the checklist (upgrades, backups, cost, observability) reviewed, that is the production readiness audit.

Licence

MIT. Maintained by Oreon IT.

Deploy kyverno-production-policies with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has kyverno-production-policies 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-production-policies is pinned at v0.1.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