騰訊雲默認kubelet工做目錄在/var/lib/kubelet使用的是系統盤,系統盤通常不夠大也不方便擴容,因此須要修改kubelet工做目錄。大概流程以下:node
準備工做web
驅逐節點docker
修改配置swift
重啓服務vim
解封節點centos
準備工做
查找kubelet啓動文件,通常配置信息在啓動文件中api
[root@VM_8_9_centos ~]# locate kubelet.service /etc/systemd/system/multi-user.target.wants/kubelet.service /usr/lib/systemd/system/kubelet.service [root@VM_8_9_centos ~]# ls -lh /usr/lib/systemd/system/kubelet.service [root@VM_8_9_centos ~]# ls -lh /etc/systemd/system/multi-user.target.wants/kubelet.service lrwxrwxrwx 1 root root 39 Sep 25 11:59 /etc/systemd/system/multi-user.target.wants/kubelet.service -> /usr/lib/systemd/system/kubelet.service [root@VM_8_9_centos ~]# cat /usr/lib/systemd/system/kubelet.service [Unit] Description=kubelet [Service] Environment=QCLOUD_NORM_URL= EnvironmentFile=-/etc/kubernetes/kubelet ExecStart=/usr/bin/kubelet ${CNI_BIN_DIR} ${KUBE_RESERVED} ${MAX_PODS} ${CLOUD_PROVIDER} ${CLOUD_CONFIG} ${POD_INFRA_CONTAINER_IMAGE} ${CLUSTER_DOMAIN} ${ALLOW_PRIVILEGED} ${REGISTER_SCHEDULABLE} ${FAIL_SWAP_ON} ${ANONYMOUS_AUTH} ${IMAGE_PULL_PROGRESS_DEADLINE} ${HOSTNAME_OVERRIDE} ${EVICTION_HARD} ${AUTHENTICATION_TOKEN_WEBHOOK} ${CLIENT_CA_FILE} ${AUTHORIZATION_MODE} ${CLUSTER_DNS} ${NON_MASQUERADE_CIDR} ${NETWORK_PLUGIN} ${KUBECONFIG} ${V} ExecStartPost=-/bin/bash /etc/kubernetes/deny-tcp-port-10250.sh Restart=always RestartSec=10 LimitNOFILE=65536 [Install] WantedBy=multi-user.target
根據啓動文件發現環境文件在kubelet中bash
[root@VM_8_9_centos ~]# cat /etc/kubernetes/kubelet CNI_BIN_DIR="--cni-bin-dir=/opt/cni/bin/" KUBE_RESERVED="--kube-reserved=cpu=90m,memory=1830Mi" MAX_PODS="--max-pods=253" CLOUD_PROVIDER="--cloud-provider=qcloud" CLOUD_CONFIG="--cloud-config=/etc/kubernetes/qcloud.conf" POD_INFRA_CONTAINER_IMAGE="--pod-infra-container-image=ccr.ccs.tencentyun.com/library/pause:latest" CLUSTER_DOMAIN="--cluster-domain=cluster.local" ALLOW_PRIVILEGED="--allow-privileged=true" REGISTER_SCHEDULABLE="--register-schedulable=true" FAIL_SWAP_ON="--fail-swap-on=false" ANONYMOUS_AUTH="--anonymous-auth=false" IMAGE_PULL_PROGRESS_DEADLINE="--image-pull-progress-deadline=10m0s" HOSTNAME_OVERRIDE="--hostname-override=192.168.8.9" EVICTION_HARD="--eviction-hard=nodefs.available<10%,nodefs.inodesFree<5%,imagefs.available<15%,memory.available<100Mi" AUTHENTICATION_TOKEN_WEBHOOK="--authentication-token-webhook=true" CLIENT_CA_FILE="--client-ca-file=/etc/kubernetes/cluster-ca.crt" AUTHORIZATION_MODE="--authorization-mode=Webhook" CLUSTER_DNS="--cluster-dns=172.16.255.48" NON_MASQUERADE_CIDR="--non-masquerade-cidr=0.0.0.0/0" NETWORK_PLUGIN="--network-plugin=cni" KUBECONFIG="--kubeconfig=/etc/kubernetes/kubelet-kubeconfig" V="--v=2"
驅逐節點
驅逐會自動封鎖節點(將節點內pod驅逐到集羣中其餘節點上,不影響集羣使用,DaemonSet pod除外),驅逐後會檢查節點爲不可調度狀態dom
[root@VM_8_9_centos ~]# kubectl drain 192.168.8.9 node/192.168.8.9 cordoned error: unable to drain node "192.168.8.9", aborting command... There are pending nodes to be drained: 192.168.8.9 error: DaemonSet-managed pods (use --ignore-daemonsets to ignore): rancher-logging-fluentd-tlqnq, rancher-logging-log-aggregator-m5g69, registry-proxy-xkmk5, exporter-node-cluster-monitoring-t5jj7, cattle-node-agent-j8wcn, ccs-log-collector-x57f8, ip-masq-agent-xt9q2, tke-bridge-agent-8rxgl, tke-cni-agent-lvv98; pods with local storage (use --delete-local-data to override): coupon-service-1, yuedi-passenger-api-1, coupon-service-1, rental-api-1, passenger-api-0, eureka-1, service-9777bd6ff-bsnj7, rental-service-0, passenger-api-0, swift-778d866966-c6nk7 [root@VM_8_9_centos ~]# kubectl get nodes NAME STATUS ROLES AGE VERSION 192.168.8.14 Ready <none> 89d v1.12.4-tke.10 192.168.8.15 Ready <none> 181d v1.12.4-tke.3 192.168.8.3 Ready <none> 181d v1.12.4-tke.3 192.168.8.4 Ready <none> 181d v1.12.4-tke.3 192.168.8.9 Ready,SchedulingDisabled <none> 89d v1.12.4-tke.10 [root@VM_8_9_centos ~]# ls /data/ docker kubelet lost+found
修改配置
修改kubelet配置文件第一行添加kubelet 目錄參數tcp
[root@VM_8_9_centos ~]# head -n 1 /etc/kubernetes/kubelet ROOT_DIR="--root-dir=/data/kubelet"
修改啓動配置文件添加ROOT_DIR參數
[root@VM_8_9_centos ~]# vim /usr/lib/systemd/system/kubelet.service ExecStart=/usr/bin/kubelet ${ROOT_DIR} ${CNI_BIN_DIR} ${KUBE_RESERVED} ${MAX_PODS} ${CLOUD_PROVIDER} ${CLOUD_CONFIG} ${POD_INFRA_CONTAINER_IMAGE} ${CLUSTER_DOMAIN} ${ALLOW_PRIVILEGED} ${REGISTER_SCHEDULABLE} ${FAIL_SWAP_ON} ${ANONYMOUS_AUTH} ${IMAGE_PULL_PROGRESS_DEADLINE} ${HOSTNAME_OVERRIDE} ${EVICTION_HARD} ${AUTHENTICATION_TOKEN_WEBHOOK} ${CLIENT_CA_FILE} ${AUTHORIZATION_MODE} ${CLUSTER_DNS} ${NON_MASQUERADE_CIDR} ${NETWORK_PLUGIN} ${KUBECONFIG} ${V}
重啓服務
[root@VM_8_9_centos ~]# systemctl daemon-reload [root@VM_8_9_centos ~]# systemctl restart kubelet [root@VM_8_9_centos ~]# systemctl status kubelet -l ● kubelet.service - kubelet Loaded: loaded (/usr/lib/systemd/system/kubelet.service; enabled; vendor preset: disabled)ls / Active: active (running) since Mon 2019-12-23 16:38:04 CST; 1min 2s ago Process: 24745 ExecStartPost=/bin/bash /etc/kubernetes/deny-tcp-port-10250.sh (code=exited, status=0/SUCCESS) Main PID: 24744 (kubelet) Tasks: 26 Memory: 49.2M CGroup: /system.slice/kubelet.service └─24744 /usr/bin/kubelet --root-dir=/data/kubelet --cni-bin-dir=/opt/cni/bin/ --kube-reserved=cpu=90m,memory=1830Mi --max-pods=253 --cloud-provider=qcloud --cloud-config=/etc/kubernetes/qcloud.conf --pod-infra-container-image=ccr.ccs.tencentyun.com/library/pause:latest --cluster-domain=cluster.local --allow-privileged=true --register-schedulable=true --fail-swap-on=false --anonymous-auth=false --image-pull-progress-deadline=10m0s --hostname-override=192.168.8.9 --eviction-hard=nodefs.available<10%,nodefs.inodesFree<5%,imagefs.available<15%,memory.available<100Mi --authentication-token-webhook=true --client-ca-file=/etc/kubernetes/cluster-ca.crt --authorization-mode=Webhook --cluster-dns=172.16.255.48 --non-masquerade-cidr=0.0.0.0/0 --network-plugin=cni --kubeconfig=/etc/kubernetes/kubelet-kubeconfig --v=2
取消封鎖
[root@VM_8_9_centos ~]# kubectl uncordon 192.168.8.9 node/192.168.8.9 uncordoned
驗證效果
查看節點信息正常
[root@VM_8_9_centos ~]# kubectl get nodes NAME STATUS ROLES AGE VERSION 192.168.8.14 Ready <none> 89d v1.12.4-tke.10 192.168.8.15 Ready <none> 181d v1.12.4-tke.3 192.168.8.3 Ready <none> 181d v1.12.4-tke.3 192.168.8.4 Ready <none> 181d v1.12.4-tke.3 192.168.8.9 Ready <none> 89d v1.12.4-tke.10
新建kubelet目錄在data下
[root@VM_8_9_centos ~]# ls /data/kubelet/ cpu_manager_state plugin-containers plugins pods [root@VM_8_9_centos ~]# du -sh /data/kubelet/ 480K /data/kubelet/