All Policies
Add imagePullSecrets for Containers and InitContainers
Images coming from certain registries require authentication in order to pull them, and the kubelet uses this information in the form of an imagePullSecret to pull those images on behalf of your Pod. This policy searches for images coming from a registry called `corp.reg.com` referenced by either one of the containers or one of the init containers and, if found, will mutate the Pod to add an imagePullSecret called `my-secret`.
Policy Definition
/other/add-imagepullsecrets-for-containers-and-initcontainers.yaml
1apiVersion: kyverno.io/v1
2kind: ClusterPolicy
3metadata:
4 name: add-imagepullsecrets-for-containers-and-initcontainers
5 annotations:
6 policies.kyverno.io/title: Add imagePullSecrets for Containers and InitContainers
7 policies.kyverno.io/category: Sample
8 policies.kyverno.io/subject: Pod
9 policies.kyverno.io/minversion: 1.3.6
10 policies.kyverno.io/description: >-
11 Images coming from certain registries require authentication in order to pull them,
12 and the kubelet uses this information in the form of an imagePullSecret to pull
13 those images on behalf of your Pod. This policy searches for images coming from a
14 registry called `corp.reg.com` referenced by either one of the containers or one
15 of the init containers and, if found, will mutate the Pod to add an
16 imagePullSecret called `my-secret`.
17spec:
18 rules:
19 - name: add-imagepullsecret
20 match:
21 resources:
22 kinds:
23 - Pod
24 preconditions:
25 any:
26 - key: "corp.reg.com"
27 operator: In
28 value: "{{ images.initContainers.*.registry || `[]` }}"
29 - key: "corp.reg.com/*"
30 operator: In
31 value: "{{ images.containers.*.registry }}"
32 mutate:
33 patchStrategicMerge:
34 spec:
35 imagePullSecrets:
36 - name: my-secret
37