Skip to content

Commit 9237e7e

Browse files
authored
Add Kyverno policy to require instance label on Pods
1 parent 0ac8a8a commit 9237e7e

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

kyverno-sample.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
apiVersion: kyverno.io/v1
2+
kind: ClusterPolicy
3+
metadata:
4+
name: require-instance-label
5+
spec:
6+
# Block the resource creation if the policy is violated
7+
validationFailureAction: Enforce
8+
rules:
9+
- name: check-for-instance-label
10+
match:
11+
# Match any request to create or update a Pod
12+
any:
13+
- resources:
14+
kinds:
15+
- Pod
16+
validate:
17+
message: "All Pods must have the label 'app.kubernetes.io/instance'."
18+
# The pattern ensures the label exists and has any non-empty value
19+
pattern:
20+
metadata:
21+
labels:
22+
app.kubernetes.io/instance: "?*"

0 commit comments

Comments
 (0)