Skip to content

Commit

Permalink
sysctl: add chart to allow us to configure worker kernel params
Browse files Browse the repository at this point in the history
As reported in "Understand why system CPU usage is so high"[1], we see
that the kernel spends a lot of time trying to reclaim memory for itself
when a bunch of containers start running on those VMs.

By adjusting the minimum amount of reserved memory for the kernel to a
higher value, we're able to then let it do less work.

With the introduction of the `sysctl` chart, every time a new `worker`
node gets in, the pod in the daemonset will get scheduled to it, thus,
the parameters we want will be set on such selected set of nodes.

[1]: #22

Signed-off-by: Ciro S. Costa <[email protected]>
  • Loading branch information
Ciro S. Costa committed May 11, 2019
1 parent c175729 commit e88741a
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 0 deletions.
22 changes: 22 additions & 0 deletions deployments/without-creds/sysctl/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
5 changes: 5 additions & 0 deletions deployments/without-creds/sysctl/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: v1
appVersion: "1.0"
description: A Helm Chart for configuring kernel parameters
name: sysctl
version: 0.1.0
Empty file.
32 changes: 32 additions & 0 deletions deployments/without-creds/sysctl/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "sysctl.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "sysctl.fullname" -}}
{{- if .Values.fullnameOverride -}}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- if contains $name .Release.Name -}}
{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- end -}}
{{- end -}}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "sysctl.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}
52 changes: 52 additions & 0 deletions deployments/without-creds/sysctl/templates/daemonset.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: {{ include "sysctl.fullname" . }}
labels:
app.kubernetes.io/name: {{ include "sysctl.name" . }}
helm.sh/chart: {{ include "sysctl.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
spec:
selector:
matchLabels:
app.kubernetes.io/name: {{ include "sysctl.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
template:
metadata:
labels:
app.kubernetes.io/name: {{ include "sysctl.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
spec:
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
securityContext:
privileged: true
terminationGracePeriodSeconds: '5'
command:
- /bin/sh
- -c
- |
set -o errexit
set -o xtrace
{{- if empty .Values.sysctl }}
{{ fail "at least one sysctl option must be set." }}
{{- end }}
while sysctl -w {{ range .Values.sysctl }}{{ . }}{{- end }}
do
sleep 120s
done
resources:
{{- toYaml .Values.resources | nindent 12 }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
30 changes: 30 additions & 0 deletions deployments/without-creds/sysctl/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
image:
repository: busybox
tag: latest
pullPolicy: IfNotPresent

nameOverride: ""
fullnameOverride: ""

resources:
limits:
cpu: 50m
memory: 20Mi
requests:
cpu: 50m
memory: 20Mi

nodeSelector:
cloud.google.com/gke-nodepool: workers-1

affinity: {}

# A list of `sysctl` values to configure.
# For instance:
#
# sysctl: [ "vm.min_free_kbytes=7852" ]
#
# Note: at least one value must be configured.
#
sysctl:
- vm.min_free_kbytes=1000000

0 comments on commit e88741a

Please sign in to comment.