Skip to content

Yuvraj 🧢

Generate polices ! Make Kubernetes life hassle free with Kyverno - Part 2

kubernetes, kyverno1 min read

In the last blog post, we discussed the basics of a Kyverno generate policy and synchronization feature for managing resources across namespaces. The last demo was limited because at that time Kyverno only supported the create resource trigger for generate policies.

last Friday Kyverno roll out a new release with some exciting features. Let's explore generate policy with some use cases. We will also discuss the best practices before upgrading. Don't worry this release is backward compatible


Kyverno generates resources based on a given set of conditions or triggers (read more about match/exclude). A Kyverno generate policy supports two types of rules. In my last blog I described these two types in detail Generate polices ! Make Kubernetes life hassle free with Kyverno

With the new release users can now users can add selector to policy for creating a trigger.

In our first use case, we will generate resources based on adding a namespace label.

As an example, we will use Velero which is a tool from VMware for managing backups of Kubernetes configuration and state. Take a look at this TGIK session on Velero - it's an interesting tool

Here we will create a trigger on namespace labels. The namespace owner owner can enable or disable Velero backup by adding or removing the label i.e. nirmata.io/auto-backup: enabled

As another example we can write a policy that enable Prometheus, a CNCF metrics and alerting tool, for a namespace. Here we will create a trigger on namespace labels. The namespace owner request a service account for Prometheus by adding or removing the label i.e. nirmata.io/monitoring: enabled

Let's see a demo, but before demo let's provide Kyverno specific permissions for both use cases. Also create a namespace velero because our policy will create schedule in velero.

Let's see in action

kyverno

Note : we advise you to use a generate policy with a selector. If you are using generate policy without selector then it will work fine because we have backward compatibility. we will deprecate older functionality in the next major release.


Check out the Kyverno v1.1.12 GitHub page to learn more about the new feature added in Kyverno like Kustomize support for patches,Namespaced policies and some cli improvment for local testing. Find more about Kyverno in the previous post Kubernetes Policy Management with Kyverno..