Generate polices ! Make Kubernetes life hassle free with Kyverno - Part 2
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.
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.
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.
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
Let's see in action
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..