我通过Kubernetes部署Redis容器并收到以下警告:
警告您在内核中启用了透明大页(THP)支持。这将导致Redis的延迟和内存使用问题。要解决此问题,请运行命令' echo never> / SYS /内核/毫米/ transparent_hugepage /启用'以root用户身份将其添加到/etc/rc.local中,以便在重新启动后保留设置。禁用THP后必须重新启动Redis
是否可以通过Kubernetes禁用THP?也许是通过init-containers?
答案 0 :(得分:11)
是的,使用init-containers,它非常简单:
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"]
演示(请注意,这是系统范围的设置):
$ 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]
答案 1 :(得分:1)
哎,
我不知道我做了什么是个好主意,但我们需要在所有K8S虚拟机上为所有应用停用THP。所以我使用DaemonSet而不是在我们所有的堆栈中添加一个init-container:
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: thp-disable
namespace: kube-system
spec:
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"]
我觉得它有点脏但是有效。