kubelet-1.9 MemoryAccounting CPUAccounting not enabled for pid

升级kubelet到1.9,启动notes上kublet的时候报错,MemoryAccounting not enabled for pid: 8586 CPUAccounting not enabled for pid: 7296,找了下原因,如下是解决办法:

因为kubelet启动报错,执行systemctl status kubelet看看出错的日志情况:

# systemctl status kubelet
● kubelet.service - Kubernetes Kubelet Server
   Loaded: loaded (/usr/lib/systemd/system/kubelet.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since 二 2018-03-13 08:56:02 CST; 26min ago
     Docs: https://github.com/GoogleCloudPlatform/kubernetes
 Main PID: 8586 (code=exited, status=1/FAILURE)

3月 13 08:50:12 k04-07-vm01 kubelet[8586]: W0313 08:50:12.374880    8586 container_manager_linux.go:744] MemoryAccounting not enabled for pid: 8586
3月 13 08:55:12 k04-07-vm01 kubelet[8586]: W0313 08:55:12.375374    8586 container_manager_linux.go:741] CPUAccounting not enabled for pid: 7296
3月 13 08:55:12 k04-07-vm01 kubelet[8586]: W0313 08:55:12.375427    8586 container_manager_linux.go:744] MemoryAccounting not enabled for pid: 7296
3月 13 08:55:12 k04-07-vm01 kubelet[8586]: W0313 08:55:12.375625    8586 container_manager_linux.go:741] CPUAccounting not enabled for pid: 8586
3月 13 08:55:12 k04-07-vm01 kubelet[8586]: W0313 08:55:12.375651    8586 container_manager_linux.go:744] MemoryAccounting not enabled for pid: 8586
3月 13 08:56:02 k04-07-vm01 systemd[1]: Stopping Kubernetes Kubelet Server...
3月 13 08:56:02 k04-07-vm01 systemd[1]: kubelet.service: main process exited, code=exited, status=1/FAILURE
3月 13 08:56:02 k04-07-vm01 systemd[1]: Stopped Kubernetes Kubelet Server.
3月 13 08:56:02 k04-07-vm01 systemd[1]: Unit kubelet.service entered failed state.
3月 13 08:56:02 k04-07-vm01 systemd[1]: kubelet.service failed.

解决办法是增加一个配置文件,明确启用DefaultCPUAccounting和DefaultMemoryAccounting。

mkdir -p /etc/systemd/system.conf.d
cat <<EOF >/etc/systemd/system.conf.d/kubernetes-accounting.conf
[Manager]
DefaultCPUAccounting=yes
DefaultMemoryAccounting=yes  
EOF

systemctl daemon-reload
systemctl enable kubelet
systemctl start kubelet