All Policies
Enforce pod duration
This validation is valuable when annotations are used to define durations, such as to ensure a Pod lifetime annotation does not exceed some site specific max threshold. Pod lifetime annotation can be no greater than 8 hours.
Policy Definition
/other/pod_lifetime_annotation/enforce_pod_duration.yaml
1apiVersion: kyverno.io/v1
2kind: ClusterPolicy
3metadata:
4 name: pod-lifetime
5 annotations:
6 policies.kyverno.io/title: Enforce pod duration
7 policies.kyverno.io/category: Sample
8 policies.kyverno.io/minversion: 1.4.2
9 policies.kyverno.io/subject: Pod
10 policies.kyverno.io/description: >-
11 This validation is valuable when annotations are used to define durations,
12 such as to ensure a Pod lifetime annotation does not exceed some site specific max threshold.
13 Pod lifetime annotation can be no greater than 8 hours.
14spec:
15 validationFailureAction: audit
16 background: true
17 rules:
18 - name: pods-lifetime
19 match:
20 resources:
21 kinds:
22 - Pod
23 validate:
24 message: "Pod lifetime exceeds limit of 8h"
25 deny:
26 conditions:
27 any:
28 - key: "{{ request.object.metadata.annotations.\"pod.kubernetes.io/lifetime\" }}"
29 operator: GreaterThan
30 value: "8h"
31