Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable Transparent Huge Pages from Kubernetes

I deploy Redis container via Kubernetes and get the following warning:

WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled

Is it possible to disable THP via Kubernetes? Perhaps via init-containers?

like image 263
chingis Avatar asked Jul 24 '17 11:07

chingis


1 Answers

Yes, with init-containers it's quite straightforward:

apiVersion: v1
kind: Pod
metadata:
  name: thp-test
spec:
  restartPolicy: Never
  terminationGracePeriodSeconds: 1
  volumes:
    - name: host-sys
      hostPath:
        path: /sys
  initContainers:
    - name: disable-thp
      image: busybox
      volumeMounts:
        - name: host-sys
          mountPath: /host-sys
      command: ["sh", "-c", "echo never >/host-sys/kernel/mm/transparent_hugepage/enabled"]
  containers:
    - name: busybox
      image: busybox
      command: ["cat", "/sys/kernel/mm/transparent_hugepage/enabled"]

Demo (notice that this is a system wide setting):

$ ssh THATNODE cat /sys/kernel/mm/transparent_hugepage/enabled
always [madvise] never
$ kubectl create -f thp-test.yaml
pod "thp-test" created
$ kubectl logs thp-test
always madvise [never]
$ kubectl delete pod thp-test
pod "thp-test" deleted
$ ssh THATNODE cat /sys/kernel/mm/transparent_hugepage/enabled
always madvise [never]
like image 172
Janos Lenart Avatar answered Oct 13 '22 17:10

Janos Lenart