Back to Policies

Add Karpenter Do Not Evict

If a Pod exists with the annotation `karpenter.sh/do-not-evict: true` on a Node, and a request is made to delete the Node, Karpenter will not drain any Pods from that Node or otherwise try to delete the Node. This is useful for Pods that should run uninterrupted to completion. This policy mutates Jobs and CronJobs so that Pods spawned by them will contain the `karpenter.sh/do-not-evict: true` annotation.

View on GitHub

Policy Definition

apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: add-karpenter-donot-evict
annotations:
policies.kyverno.io/title: Add Karpenter Do Not Evict
policies.kyverno.io/category: Karpenter, EKS Best Practices
policies.kyverno.io/severity: medium
policies.kyverno.io/subject: Pod
kyverno.io/kyverno-version: 1.7.1
policies.kyverno.io/minversion: 1.6.0
kyverno.io/kubernetes-version: "1.23"
policies.kyverno.io/description: "If a Pod exists with the annotation `karpenter.sh/do-not-evict: true` on a Node, and a request is made to delete the Node, Karpenter will not drain any Pods from that Node or otherwise try to delete the Node. This is useful for Pods that should run uninterrupted to completion. This policy mutates Jobs and CronJobs so that Pods spawned by them will contain the `karpenter.sh/do-not-evict: true` annotation."
spec:
rules:
- name: do-not-evict-jobs
match:
any:
- resources:
kinds:
- Job
mutate:
patchStrategicMerge:
spec:
template:
metadata:
annotations:
karpenter.sh/do-not-evict: "true"
- name: do-not-evict-cronjobs
match:
any:
- resources:
kinds:
- CronJob
mutate:
patchStrategicMerge:
spec:
jobTemplate:
spec:
template:
metadata:
annotations:
karpenter.sh/do-not-evict: "true"

Related Policies