背景信息
OS为Ubuntu 16.04,该版本默认提供了systemctl工具,kubelet就通过该工具来管理。
root@ubuntu2:/etc/# systemctl --version
systemd 229
+PAM +AUDIT +SELINUX +IMA +APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ -LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD -IDN
先记住几个命令:
启动kubelet :systemctl start kubelet
停止kubelet:systemctl stop kubelet
重新载入systemd:systemctl daemon-reload
既然是通过systemctl来管理的,因此可以在/etc/systemd/system/目录下找对应服务的配置文件目录,例如kubelet的相关配置的保存目录为:/etc/systemd/system/kubelet.service.d/10-kubeadm.conf,默认配置如下所示:
root@ubuntu2:/etc/systemd/system/kubelet.service.d# cat 10-kubeadm.conf
[Service]
Environment="KUBELET_KUBECONFIG_ARGS=--kubeconfig=/etc/kubernetes/kubelet.conf --require-kubeconfig=true"
Environment="KUBELET_SYSTEM_PODS_ARGS=--pod-manifest-path=/etc/kubernetes/manifests --allow-privileged=true"
Environment="KUBELET_NETWORK_ARGS=--network-plugin=cni --cni-conf-dir=/etc/cni/net.d --cni-bin-dir=/opt/cni/bin"
Environment="KUBELET_DNS_ARGS=--cluster-dns=100.64.0.10 --cluster-domain=cluster.local"
Environment="KUBELET_EXTRA_ARGS=--v=4"
ExecStart=
ExecStart=/usr/bin/kubelet $KUBELET_KUBECONFIG_ARGS $KUBELET_SYSTEM_PODS_ARGS $KUBELET_NETWORK_ARGS $KUBELET_DNS_ARGS $KUBELET_EXTRA_ARGS
查看kubelet的相关启动参数:
root@ubuntu2:/etc/systemd/system/kubelet.service.d# ps -ef | grep kubelet
root 36457 1 4 07:06 ? 00:00:49 /usr/bin/kubelet --kubeconfig=/etc/kubernetes/kubelet.conf --require-kubeconfig=true --pod-manifest-path=/etc/kubernetes/manifests --allow-privileged=true --network-plugin=cni --cni-conf-dir=/etc/cni/net.d --cni-bin-dir=/opt/cni/bin --cluster-dns=100.64.0.10 --cluster-domain=cluster.local --v=4
root 49224 47905 0 07:26 pts/1 00:00:00 grep --color=auto kubelet
可以看出与配置文件中的设置是一致的。
kubelet配置参数修改示例
添加一个新的参数,如加粗部分所示
root@ubuntu2:/etc/systemd/system/kubelet.service.d# vi 10-kubeadm.conf
[Service]
Environment="KUBELET_KUBECONFIG_ARGS=--kubeconfig=/etc/kubernetes/kubelet.conf --require-kubeconfig=true"
Environment="KUBELET_SYSTEM_PODS_ARGS=--pod-manifest-path=/etc/kubernetes/manifests --allow-privileged=true"
Environment="KUBELET_NETWORK_ARGS=--network-plugin=cni --cni-conf-dir=/etc/cni/net.d --cni-bin-dir=/opt/cni/bin"
Environment="KUBELET_DNS_ARGS=--cluster-dns=100.64.0.10 --cluster-domain=cluster.local"
Environment="KUBELET_EXTRA_ARGS=--v=4"
Environment="DEF_ARGS=--max-pods=40"
ExecStart=
ExecStart=/usr/bin/kubelet $KUBELET_KUBECONFIG_ARGS $KUBELET_SYSTEM_PODS_ARGS $KUBELET_NETWORK_ARGS $KUBELET_DNS_ARGS $KUBELET_EXTRA_ARGS $DEF_ARGS
执行如下命令使新增参数生效:
停止kubelet:systemctl stop kubelet
重新载入systemd:systemctl daemon-reload
启动kubelet :systemctl start kubelet
检查参数是否已经生效:
root@ubuntu2:/etc/systemd/system/kubelet.service.d# ps -ef | grep kubelet
root 36457 1 4 07:06 ? 00:00:49 /usr/bin/kubelet --kubeconfig=/etc/kubernetes/kubelet.conf --require-kubeconfig=true --pod-manifest-path=/etc/kubernetes/manifests --allow-privileged=true --network-plugin=cni --cni-conf-dir=/etc/cni/net.d --cni-bin-dir=/opt/cni/bin --cluster-dns=100.64.0.10 --cluster-domain=cluster.local --v=4 --max-pods=40
root 49224 47905 0 07:26 pts/1 00:00:00 grep --color=auto kubelet