1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2024-12-15 17:51:20 +00:00
kyverno/samples/AddSafeToEvict.md

50 lines
1.3 KiB
Markdown
Raw Normal View History

2019-11-06 00:45:37 +00:00
# Mutate pods with `emptyDir` and `hostPath` with `safe-to-evict`
The Kubernetes cluster autoscaler does not evict pods that use `hostPath` or `emptyDir` volumes. To allow eviction of these pods, the following annotation must be added to the pods:
````yaml
cluster-autoscaler.kubernetes.io/safe-to-evict: true
````
This policy matches and mutates pods with `emptyDir` and `hostPath` volumes, to add the `safe-to-evict` annotation if it is not specified.
## Policy YAML
2019-11-09 03:25:43 +00:00
[add_safe_to_evict_annotation.yaml](best_practices/add_safe_to_evict.yaml)
2019-11-06 00:45:37 +00:00
````yaml
2019-12-10 17:51:15 +00:00
apiVersion: kyverno.io/v1
2019-12-09 23:33:21 +00:00
kind: ClusterPolicy
2019-11-06 00:45:37 +00:00
metadata:
2019-12-10 17:51:15 +00:00
name: add-safe-to-evict
2019-11-06 00:45:37 +00:00
spec:
rules:
2019-11-09 03:02:49 +00:00
- name: "annotate-empty-dir"
2019-11-06 00:45:37 +00:00
match:
resources:
kinds:
2019-12-10 17:51:15 +00:00
- Pod
2019-11-06 00:45:37 +00:00
mutate:
overlay:
metadata:
annotations:
+(cluster-autoscaler.kubernetes.io/safe-to-evict): true
spec:
volumes:
- (emptyDir): {}
2019-12-10 17:51:15 +00:00
- name: annotate-host-path
2019-11-06 00:45:37 +00:00
match:
resources:
kinds:
2019-12-10 17:51:15 +00:00
- Pod
2019-11-06 00:45:37 +00:00
mutate:
overlay:
metadata:
annotations:
+(cluster-autoscaler.kubernetes.io/safe-to-evict): true
spec:
volumes:
- (hostPath):
path: "*"
2019-12-10 17:51:15 +00:00
````