[stable/redis] Added sysctl init container (#10723)

* [stable/redis] Added sysctl init container

Made it possible to change host kernel settings with a custom
init container.
Fixes https://github.com/helm/charts/issues/10666

Signed-off-by: Denis Vilar <denisvilar@gmail.com>

* [stable/redis] Fixes according to review comments

* single sysctlImage config values for both master and slave
* use `bitnami/minideb` image
* added CI values

Signed-off-by: Denis Vilar <denisvilar@gmail.com>

* changed sysctl container command in CI production values

Signed-off-by: Denis Vilar <denisvilar@gmail.com>

* [stable/redis] Fixed indentation issue

Signed-off-by: Denis Vilar <denisvilar@gmail.com>
This commit is contained in:
Denis Vilar
2019-01-25 08:22:23 -08:00
committed by Kubernetes Prow Robot
parent 27829dedd5
commit fbbc551e33
8 changed files with 109 additions and 2 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
name: redis
version: 5.3.0
version: 5.4.0
appVersion: 4.0.12
description: Open source, advanced key-value store. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets and sorted sets.
keywords:
+23
View File
@@ -200,6 +200,13 @@ The following table lists the configurable parameters of the Redis chart and the
| `slave.resources` | Redis slave CPU/Memory resource requests/limits | `master.resources` |
| `slave.affinity` | Enable node/pod affinity for slaves | {} |
| `slave.priorityClassName` | Redis Slave pod priorityClassName | {} |
| `sysctlImage.enabled` | Enable an init container to modify Kernel settings | `false` |
| `sysctlImage.command` | sysctlImage command to execute | [] |
| `sysctlImage.registry` | sysctlImage Init container registry | `docker.io` |
| `sysctlImage.repository` | sysctlImage Init container name | `bitnami/minideb` |
| `sysctlImage.tag` | sysctlImage Init container tag | `latest` |
| `sysctlImage.pullPolicy` | sysctlImage Init container pull policy | `Always` |
| `sysctlImage.mountHostSys` | Mount the host `/sys` folder to `/host-sys` | `false` |
Specify each parameter using the `--set key=value[,key=value]` argument to `helm install`. For example,
@@ -253,3 +260,19 @@ $ helm install --set persistence.existingClaim=PVC_NAME stable/redis
## Metrics
The chart optionally can start a metrics exporter for [prometheus](https://prometheus.io). The metrics endpoint (port 9121) is exposed in the service. Metrics can be scraped from within the cluster using something similar as the described in the [example Prometheus scrape configuration](https://github.com/prometheus/prometheus/blob/master/documentation/examples/prometheus-kubernetes.yml). If metrics are to be scraped from outside the cluster, the Kubernetes API proxy can be utilized to access the endpoint.
## Host Kernel Settings
Redis may require some changes in the kernel of the host machine to work as expected, in particular increasing the `somaxconn` value and disabling transparent huge pages.
To do so, you can set up a privileged initContainer with the `sysctlImage` config values, for example:
```
sysctlImage:
enabled: true
mountHostSys: true
command:
- /bin/sh
- -c
- |-
install_packages systemd
sysctl -w net.core.somaxconn=10000
echo never > /host-sys/kernel/mm/transparent_hugepage/enabled
```
+11
View File
@@ -353,3 +353,14 @@ volumePermissions:
##
configmap: |-
# maxmemory-policy volatile-lru
## Sysctl InitContainer
## used to perform sysctl operation to modify Kernel settings (needed sometimes to avoid warnings)
sysctlImage:
enabled: true
mountHostSys: true
command:
- /bin/sh
- -c
- |-
echo "sample command"
+9
View File
@@ -164,3 +164,12 @@ Get the password secret.
{{- printf "%s" (include "redis.fullname" .) -}}
{{- end -}}
{{- end -}}
{{/*
Return sysctl image
*/}}
{{- define "redis.sysctl.image" -}}
{{- $registryName := default "docker.io" .Values.sysctlImage.registry -}}
{{- $tag := default "latest" .Values.sysctlImage.tag | toString -}}
{{- printf "%s/%s:%s" $registryName .Values.sysctlImage.repository $tag -}}
{{- end -}}
@@ -154,8 +154,10 @@ spec:
- name: config
mountPath: /opt/bitnami/redis/etc
{{- end }}
{{- if and ( and .Values.master.persistence.enabled (not .Values.persistence.existingClaim) ) .Values.master.securityContext.enabled }}
{{- $needsVolumePermissions := and ( and .Values.master.persistence.enabled (not .Values.persistence.existingClaim) ) .Values.master.securityContext.enabled }}
{{- if or $needsVolumePermissions .Values.sysctlImage.enabled }}
initContainers:
{{- if $needsVolumePermissions }}
- name: volume-permissions
image: "{{ template "volumePermissions.image" . }}"
imagePullPolicy: {{ default "" .Values.volumePermissions.image.pullPolicy | quote }}
@@ -167,6 +169,21 @@ spec:
mountPath: {{ .Values.master.persistence.path }}
subPath: {{ .Values.master.persistence.subPath }}
{{- end }}
{{- if .Values.sysctlImage.enabled }}
- name: init-sysctl
image: {{ template "redis.sysctl.image" . }}
{{- if .Values.sysctlImage.mountHostSys }}
volumeMounts:
- name: host-sys
mountPath: /host-sys
{{- end }}
command:
{{ toYaml .Values.sysctlImage.command | indent 10 }}
securityContext:
privileged: true
runAsUser: 0
{{- end }}
{{- end }}
volumes:
- name: health
configMap:
@@ -192,6 +209,11 @@ spec:
claimName: {{ .Values.persistence.existingClaim }}
{{- end }}
{{- end }}
{{- if .Values.sysctlImage.mountHostSys }}
- name: host-sys
hostPath:
path: /sys
{{- end }}
{{- if and .Values.master.persistence.enabled (not .Values.persistence.existingClaim) }}
volumeClaimTemplates:
- metadata:
@@ -153,6 +153,21 @@ spec:
- name: config
mountPath: /opt/bitnami/redis/etc
{{- end }}
{{- if .Values.sysctlImage.enabled }}
initContainers:
- name: init-sysctl
image: {{ template "redis.sysctl.image" . }}
{{- if .Values.sysctlImage.mountHostSys }}
volumeMounts:
- name: host-sys
mountPath: /host-sys
{{- end }}
command:
{{ toYaml .Values.sysctlImage.command | indent 10 }}
securityContext:
privileged: true
runAsUser: 0
{{- end }}
volumes:
- name: health
configMap:
@@ -170,4 +185,9 @@ spec:
{{- end }}
- name: redis-data
emptyDir: {}
{{- if .Values.sysctlImage.mountHostSys }}
- name: host-sys
hostPath:
path: /sys
{{- end }}
{{- end }}
+11
View File
@@ -376,3 +376,14 @@ volumePermissions:
##
configmap: |-
# maxmemory-policy volatile-lru
## Sysctl InitContainer
## used to perform sysctl operation to modify Kernel settings (needed sometimes to avoid warnings)
sysctlImage:
enabled: false
command: []
registry: docker.io
repository: bitnami/minideb
tag: latest
pullPolicy: Always
mountHostSys: false
+11
View File
@@ -377,3 +377,14 @@ volumePermissions:
##
configmap: |-
# maxmemory-policy volatile-lru
## Sysctl InitContainer
## used to perform sysctl operation to modify Kernel settings (needed sometimes to avoid warnings)
sysctlImage:
enabled: false
command: []
registry: docker.io
repository: bitnami/minideb
tag: latest
pullPolicy: Always
mountHostSys: false