Skip to content

Commit 4966b22

Browse files
committed
add gke preemtible termination helm chart
1 parent 6424e80 commit 4966b22

File tree

8 files changed

+256
-0
lines changed

8 files changed

+256
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.DS_Store
2+
.DS_STORE
13
/charts/*/charts
24
/charts/*/requirements.lock
35
/charts/*/*.tgz
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Patterns to ignore when building packages.
2+
# This supports shell glob matching, relative path matching, and
3+
# negation (prefixed with !). Only one pattern per line.
4+
.DS_Store
5+
# Common VCS dirs
6+
.git/
7+
.gitignore
8+
.bzr/
9+
.bzrignore
10+
.hg/
11+
.hgignore
12+
.svn/
13+
# Common backup files
14+
*.swp
15+
*.bak
16+
*.tmp
17+
*.orig
18+
*~
19+
# Various IDEs
20+
.project
21+
.idea/
22+
*.tmproj
23+
.vscode/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apiVersion: v2
2+
name: gke-node-termination-handler
3+
description: Helm chart for gracefully handling GCE VM terminations in kubernetes clusters
4+
type: application
5+
version: 0.0.1
6+
appVersion: "679e048"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# gke-node-termination-handler
2+
3+
[gke-node-termination-handler](https://github.com/GoogleCloudPlatform/k8s-node-termination-handler) is a tool for gracefully draining preemptible GCP nodes before Google automatically shuts them down.
4+
5+
## Notice
6+
> This is an updated version of the original helm chart https://artifacthub.io/packages/helm/fairwinds-stable/gke-node-termination-handler.
7+
> This chart solved error `GCE metadata "instance/scheduling/on-host-maintenance" not defined` when running on private GKE cluster, based on this github issue [#24](https://github.com/GoogleCloudPlatform/k8s-node-termination-handler/issues/24).
8+
9+
## Values
10+
11+
| Key | Type | Default | Description |
12+
|-------------------------------|---------|---------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------|
13+
| image.repository | string | `"k8s.gcr.io/gke-node-termination-handler@sha256"` | The image repository to pull from |
14+
| image.tag | string | `"aca12d17b222dfed755e28a44d92721e477915fb73211d0a0f8925a1fa847cca"` | The image tag to use |
15+
| image.pullPolicy | string | `"Always"` | The image pull policy. We recommend not changing this |
16+
| nameOverride | string | `""` | A template override for name |
17+
| fullnameOverride | string | `""` | A template override for fullname |
18+
| daemonset.updateStrategy.type | string | `"RollingUpdate"` | The daemonset update strategy |
19+
| resources | object | `{"limits":{"cpu":"150m","memory":"30Mi"},"requests":{"cpu":"150m","memory":"30Mi"}}` | A resource limit and requess block for the daemonset |
20+
| args | list | `["-v=10","--logtostderr","--exclude-pods=$(POD_NAME):$(POD_NAMESPACE)","--taint=cloud.google.com/impending-node-termination::NoSchedule"]` | Command arguments. Usually you don't need to override them. |
21+
| extraArgs | list | `[]` | Extra arguments for command. For example, "--system-pod-grace-period=14s" to wait for 14s for regular pods to terminate. |
22+
| env | object | `{"SLACK_WEBHOOK_URL":""}` | Extra environment variables. For example "SLACK_WEBHOOK_URL" |
23+
| hostNetwork | boolean | `true` | Necessary to hit the node's metadata server when using Workload Identity |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{{/* vim: set filetype=mustache: */}}
2+
{{/*
3+
Expand the name of the chart.
4+
*/}}
5+
{{- define "gke-node-termination-handler.name" -}}
6+
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
7+
{{- end -}}
8+
9+
{{/*
10+
Create a default fully qualified app name.
11+
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
12+
If release name contains chart name it will be used as a full name.
13+
*/}}
14+
{{- define "gke-node-termination-handler.fullname" -}}
15+
{{- if .Values.fullnameOverride -}}
16+
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
17+
{{- else -}}
18+
{{- $name := default .Chart.Name .Values.nameOverride -}}
19+
{{- if contains $name .Release.Name -}}
20+
{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
21+
{{- else -}}
22+
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
23+
{{- end -}}
24+
{{- end -}}
25+
{{- end -}}
26+
27+
{{/*
28+
Create chart name and version as used by the chart label.
29+
*/}}
30+
{{- define "gke-node-termination-handler.chart" -}}
31+
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
32+
{{- end -}}
33+
34+
{{/*
35+
Common labels
36+
*/}}
37+
{{- define "gke-node-termination-handler.labels" -}}
38+
app.kubernetes.io/name: {{ include "gke-node-termination-handler.name" . }}
39+
helm.sh/chart: {{ include "gke-node-termination-handler.chart" . }}
40+
app.kubernetes.io/instance: {{ .Release.Name }}
41+
{{- if .Chart.AppVersion }}
42+
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
43+
{{- end }}
44+
app.kubernetes.io/managed-by: {{ .Release.Service }}
45+
{{- end -}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
apiVersion: apps/v1
2+
kind: DaemonSet
3+
metadata:
4+
name: {{ include "gke-node-termination-handler.fullname" . }}
5+
labels:
6+
app.kubernetes.io/name: {{ include "gke-node-termination-handler.name" . }}
7+
helm.sh/chart: {{ include "gke-node-termination-handler.chart" . }}
8+
app.kubernetes.io/instance: {{ .Release.Name }}
9+
app.kubernetes.io/managed-by: {{ .Release.Service }}
10+
{{ include "gke-node-termination-handler.labels" . | indent 4 }}
11+
spec:
12+
selector:
13+
matchLabels:
14+
name: {{ include "gke-node-termination-handler.fullname" . }}
15+
updateStrategy:
16+
type: {{ .Values.daemonset.updateStrategy.type }}
17+
template:
18+
metadata:
19+
labels:
20+
name: {{ include "gke-node-termination-handler.fullname" . }}
21+
spec:
22+
# Necessary to hit the node's metadata server when using Workload Identity
23+
hostNetwork: {{ .Values.hostNetwork }}
24+
# Necessary to reboot node
25+
hostPID: true
26+
serviceAccountName: {{ include "gke-node-termination-handler.fullname" . }}
27+
affinity:
28+
nodeAffinity:
29+
# Restrict to preemptible nodes
30+
requiredDuringSchedulingIgnoredDuringExecution:
31+
nodeSelectorTerms:
32+
- matchExpressions:
33+
- key: cloud.google.com/gke-preemptible
34+
operator: Exists
35+
containers:
36+
- image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
37+
imagePullPolicy: {{ .Values.image.pullPolicy }}
38+
name: {{ .Chart.Name }}
39+
command: ["./node-termination-handler"]
40+
args:
41+
{{- concat .Values.args .Values.extraArgs | toYaml | nindent 12 }}
42+
securityContext:
43+
capabilities:
44+
# Necessary to reboot node
45+
add: ["SYS_BOOT"]
46+
env:
47+
- name: POD_NAME
48+
valueFrom:
49+
fieldRef:
50+
fieldPath: metadata.name
51+
- name: POD_NAMESPACE
52+
valueFrom:
53+
fieldRef:
54+
fieldPath: metadata.namespace
55+
{{- range $key, $value := .Values.env }}
56+
- name: {{ $key }}
57+
value: {{ $value | quote }}
58+
{{- end }}
59+
resources:
60+
{{- toYaml .Values.resources | nindent 12 }}
61+
tolerations:
62+
- effect: NoSchedule
63+
operator: Exists
64+
- effect: NoExecute
65+
operator: Exists
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
apiVersion: v1
2+
kind: ServiceAccount
3+
metadata:
4+
labels:
5+
app.kubernetes.io/name: {{ include "gke-node-termination-handler.name" . }}
6+
helm.sh/chart: {{ include "gke-node-termination-handler.chart" . }}
7+
app.kubernetes.io/instance: {{ .Release.Name }}
8+
app.kubernetes.io/managed-by: {{ .Release.Service }}
9+
name: {{ include "gke-node-termination-handler.fullname" . }}
10+
---
11+
kind: ClusterRole
12+
apiVersion: rbac.authorization.k8s.io/v1
13+
metadata:
14+
labels:
15+
app.kubernetes.io/name: {{ include "gke-node-termination-handler.name" . }}
16+
helm.sh/chart: {{ include "gke-node-termination-handler.chart" . }}
17+
app.kubernetes.io/instance: {{ .Release.Name }}
18+
app.kubernetes.io/managed-by: {{ .Release.Service }}
19+
name: {{ include "gke-node-termination-handler.fullname" . }}
20+
rules:
21+
# Allow Node Termination Handler to get and update nodes (for posting taints).
22+
- apiGroups: [""]
23+
resources: ["nodes"]
24+
verbs: ["get", "update"]
25+
# Allow Node Termination Handler to create events
26+
- apiGroups: [""]
27+
resources: ["events"]
28+
verbs: ["create"]
29+
# Allow Node Termination Handler to list and delete pods (for draining nodes)
30+
- apiGroups: [""]
31+
resources: ["pods"]
32+
verbs: ["list", "delete", "get"]
33+
---
34+
apiVersion: rbac.authorization.k8s.io/v1
35+
kind: ClusterRoleBinding
36+
metadata:
37+
labels:
38+
app.kubernetes.io/name: {{ include "gke-node-termination-handler.name" . }}
39+
helm.sh/chart: {{ include "gke-node-termination-handler.chart" . }}
40+
app.kubernetes.io/instance: {{ .Release.Name }}
41+
app.kubernetes.io/managed-by: {{ .Release.Service }}
42+
name: {{ include "gke-node-termination-handler.fullname" . }}
43+
roleRef:
44+
apiGroup: rbac.authorization.k8s.io
45+
kind: ClusterRole
46+
name: {{ include "gke-node-termination-handler.fullname" . }}
47+
subjects:
48+
- kind: ServiceAccount
49+
name: {{ include "gke-node-termination-handler.fullname" . }}
50+
namespace: {{ .Release.Namespace }}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
image:
2+
# image.repository -- The image repository to pull from
3+
repository: cikupin/gke-node-termination-handler
4+
# image.tag -- The image tag to use
5+
tag: 679e048cfc7c138859eb0613ba63580d982791be
6+
# image.pullPolicy -- The image pull policy. We recommend not changing this
7+
pullPolicy: Always
8+
9+
# nameOverride -- A template override for name
10+
nameOverride: ""
11+
# fullnameOverride -- A template override for fullname
12+
fullnameOverride: ""
13+
14+
daemonset:
15+
updateStrategy:
16+
# daemonset.updateStrategy.type -- The daemonset update strategy
17+
type: RollingUpdate
18+
19+
# resources -- A resource limit and requess block for the daemonset
20+
resources:
21+
limits:
22+
cpu: 150m
23+
memory: 30Mi
24+
requests:
25+
cpu: 150m
26+
memory: 30Mi
27+
28+
# args -- Command arguments. Usually you don't need to override them.
29+
args:
30+
- "-v=10"
31+
- "--logtostderr"
32+
- "--exclude-pods=$(POD_NAME):$(POD_NAMESPACE)"
33+
- "--taint=cloud.google.com/impending-node-termination::NoSchedule"
34+
35+
# extraArgs -- Extra arguments for command. For example, "--system-pod-grace-period=14s" to wait for 14s for regular pods to terminate.
36+
extraArgs: []
37+
38+
# env -- Extra environment variables. For example "SLACK_WEBHOOK_URL"
39+
env:
40+
SLACK_WEBHOOK_URL: ""
41+
42+
hostNetwork: true

0 commit comments

Comments
 (0)