参考连接: https://www.jianshu.com/p/fca5da540ee7
一 查找kubelet启动文件
[root@node2 ~]# locate kubelet.service
/etc/systemd/system/kubelet.service
/etc/systemd/system/multi-user.target.wants/kubelet.service
二 查看启动文件位置 为 /etc/kubernetes/kubelet.env
[root@node2 ~]# cat /etc/systemd/system/kubelet.service
[Unit]
Description=Kubernetes Kubelet Server
Documentation=https://github.com/GoogleCloudPlatform/kubernetes
After=docker.service
Wants=docker.socket
[Service]
User=root
EnvironmentFile=-/etc/kubernetes/kubelet.env
ExecStart=/usr/local/bin/kubelet \
$KUBE_LOGTOSTDERR \
$KUBE_LOG_LEVEL \
$KUBELET_API_SERVER \
$KUBELET_ADDRESS \
$KUBELET_PORT \
$KUBELET_HOSTNAME \
$KUBELET_ARGS \
$DOCKER_SOCKET \
$KUBELET_NETWORK_PLUGIN \
$KUBELET_VOLUME_PLUGIN \
$KUBELET_CLOUDPROVIDER
Restart=always
RestartSec=10s
[Install]
WantedBy=multi-user.target
三 修改配置文件
vim /etc/kubernetes/kubelet.env
写入 ROOT_DIR="--root-dir=/home/data/kubelet"
四 修改启动文件添加ROOT_DIR参数
vim /etc/systemd/system/kubelet.service
[Unit]
Description=Kubernetes Kubelet Server
Documentation=https://github.com/GoogleCloudPlatform/kubernetes
After=docker.service
Wants=docker.socket
[Service]
User=root
EnvironmentFile=-/etc/kubernetes/kubelet.env
ExecStart=/usr/local/bin/kubelet \
$ROOT_DIR \
$KUBE_LOGTOSTDERR \
$KUBE_LOG_LEVEL \
$KUBELET_API_SERVER \
$KUBELET_ADDRESS \
$KUBELET_PORT \
$KUBELET_HOSTNAME \
$KUBELET_ARGS \
$DOCKER_SOCKET \
$KUBELET_NETWORK_PLUGIN \
$KUBELET_VOLUME_PLUGIN \
$KUBELET_CLOUDPROVIDER
Restart=always
RestartSec=10s
[Install]
WantedBy=multi-user.target
五 重启服务 可以看到 --root-dir已指向指定的目录 不过我的kubelet 服务没有配置好,是disabled状态。。。
[root@node2 ~]# systemctl daemon-reload
[root@node2 ~]# systemctl restart kubelet
[root@node2 ~]# systemctl status kubelet -l
● kubelet.service - Kubernetes Kubelet Server
Loaded: loaded (/etc/systemd/system/kubelet.service; enabled; vendor preset: disabled)
Active: active (running) since 五 2021-05-28 15:04:21 CST; 6s ago
Docs: https://github.com/GoogleCloudPlatform/kubernetes
Main PID: 19654 (kubelet)
Tasks: 63
Memory: 27.6M
CGroup: /system.slice/kubelet.service
└─19654 /usr/local/bin/kubelet --root-dir=/home/data/kubelet --logtostderr=true --v=2 --node-ip=172.16.3.4 --hostname-override=node2 --bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --config=/etc/kubernetes/kubelet-config.yaml --kubeconfig=/etc/kubernetes/kubelet.conf --pod-infra-container-image=k8s.gcr.io/pause:3.1 --runtime-cgroups=/systemd/system.slice --network-plugin=cni --cni-conf-dir=/etc/cni/net.d --cni-bin-dir=/opt/cni/bin