1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-06 16:06:56 +00:00
kyverno/documentation/writing-policies.md

58 lines
2.2 KiB
Markdown
Raw Normal View History

2019-05-21 15:50:36 -07:00
<small>*[documentation](/README.md#documentation) / Writing Policies*</small>
2019-05-21 14:44:04 -07:00
2019-05-21 11:06:03 -07:00
# Writing Policies
2019-05-21 14:44:04 -07:00
A Kyverno policy contains a set of rules. Each rule matches resources by kind, name, or selectors.
````yaml
apiVersion : kyverno.io/v1alpha1
kind : Policy
metadata :
name : policy
spec :
# Each policy has a list of rules applied in declaration order
rules:
2019-06-12 13:50:08 -07:00
# Rules must have a unique name
- name: "check-pod-controller-labels"
2019-08-21 14:18:44 -07:00
# Each rule matches specific resource described by "match" field.
match:
resources:
2019-08-21 15:49:34 -07:00
kinds: # Required, list of kinds
2019-08-21 14:18:44 -07:00
- Deployment
- StatefulSet
2019-08-21 15:49:34 -07:00
name: "mongo*" # Optional, a resource name is optional. Name supports wildcards * and ?
namespaces: # Optional, list of namespaces
- devtest2
- devtest1
selector: # Optional, a resource selector is optional. Selector values support wildcards * and ?
matchLabels:
app: mongodb
matchExpressions:
- {key: tier, operator: In, values: [database]}
# Resources that need to be excluded
exclude: # Optional, resources to be excluded from evaulation
resources:
kinds:
- Daemonsets
2019-08-21 14:18:44 -07:00
name: "*"
2019-08-21 15:49:34 -07:00
namespaces:
- devtest2
2019-08-21 14:18:44 -07:00
selector:
matchLabels:
app: mongodb
matchExpressions:
- {key: tier, operator: In, values: [database]}
2019-08-21 15:49:34 -07:00
2019-05-21 14:44:04 -07:00
# Each rule can contain a single validate, mutate, or generate directive
...
````
2019-05-22 18:14:10 +03:00
Each rule can validate, mutate, or generate configurations of matching resources. A rule definition can contain only a single **mutate**, **validate**, or **generate** child node. These actions are applied to the resource in described order: mutation, validation and then generation.
2019-08-21 14:18:44 -07:00
**Resource description:**
* ```match``` is a required key that defines the parameters which identify the resources that need to matched
* ```exclude``` is an option key to exclude resources from the application of the rule
---
2019-05-21 15:50:36 -07:00
<small>*Read Next >> [Validate](/documentation/writing-policies-validate.md)*</small>