Disable Transparent Huge Pages from Kubernetes
Yes, with init-containers it's quite straightforward:
apiVersion: v1kind: Podmetadata: name: thp-testspec: 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/enabledalways [madvise] never$ kubectl create -f thp-test.yamlpod "thp-test" created$ kubectl logs thp-testalways madvise [never]$ kubectl delete pod thp-testpod "thp-test" deleted$ ssh THATNODE cat /sys/kernel/mm/transparent_hugepage/enabledalways madvise [never]
Ay,
I don't know if what I did is a good idea but we needed to deactivate THP on all our K8S VMs for all our apps. So I used a DaemonSet instead of adding an init-container to all our stacks :
apiVersion: apps/v1kind: DaemonSetmetadata: name: thp-disable namespace: kube-systemspec: selector: matchLabels: name: thp-disable template: metadata: labels: name: thp-disable spec: restartPolicy: Always 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: ["watch", "-n", "600", "cat", "/sys/kernel/mm/transparent_hugepage/enabled"]
I think it's a little dirty but it works.