K8S 之 kubelet 配置使用记录

1. 查看 OS 和 kubelet 版本信息

[root@master001 ~]# lsb_release -a
LSB Version:    :core-4.1-amd64:core-4.1-noarch:cxx-4.1-amd64:cxx-4.1-noarch:desktop-4.1-amd64:desktop-4.1-noarch:languages-4.1-amd64:languages-4.1-noarch:printing-4.1-amd64:printing-4.1-noarch
Distributor ID: CentOS
Description:    CentOS Linux release 7.6.1810 (Core)
Release:        7.6.1810
Codename:       Core
[root@master001 ~]# kubelet --version
Kubernetes v1.16.3

2. CentOS7 主机 systemctl 与 kubelet 关系

systemd 的配置文件主要放在/usr/lib/systemd/system目录,也可能在/etc/systemd/system目录。
如果kubelet是通过systemctl管理的,应该可以在systemctl管理目录中找到其配置文件。

2.1 验证 kubelet 是否通过 systemctl 管理

# systemctl status kubelet
● kubelet.service - kubelet: The Kubernetes Node Agent
   Loaded: loaded (/usr/lib/systemd/system/kubelet.service; enabled; vendor preset: disabled)
  Drop-In: /usr/lib/systemd/system/kubelet.service.d
           └─10-kubeadm.conf
   Active: active (running) since Wed 2020-01-08 13:48:29 CST; 1 months 17 days ago
     Docs: https://kubernetes.io/docs/
 Main PID: 54019 (kubelet)
    Tasks: 29
   Memory: 71.8M
   CGroup: /system.slice/kubelet.service
           └─54019 /usr/bin/kubelet --bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --kubeconfig=/etc/kubernetes/kubelet.conf --config=/var...

2.2 (方法一) 查找 kubelet 配置文件

如下参数说明

  • Environment=“KUBELET_CONFIG_ARGS=–config=/var/lib/kubelet/config.yaml” 配置文件位置
$ cd /usr/lib/systemd/system	# Centos系统 systemctl 管理目录
$ ls -lrt | grep kubelet		# kubelet 部分文件
-rw-r--r--. 1 root root  222 Nov 14 04:22 kubelet.service
drwxr-xr-x. 2 root root   29 Dec 30 16:46 kubelet.service.d
$ cd kubelet.service.d/
$ ls -lrt						# kubelet 初始配置文件
total 4
-rw-r--r--. 1 root root 900 Nov 14 04:22 10-kubeadm.conf
$ cat 10-kubeadm.conf			# 查看和修改 kubelet 配置文件
# Note: This dropin only works with kubeadm and kubelet v1.11+
[Service]
Environment="KUBELET_KUBECONFIG_ARGS=--bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --kubeconfig=/etc/kubernetes/kubelet.conf"
Environment="KUBELET_CONFIG_ARGS=--config=/var/lib/kubelet/config.yaml"
# This is a file that "kubeadm init" and "kubeadm join" generates at runtime, populating the KUBELET_KUBEADM_ARGS variable dynamically
EnvironmentFile=-/var/lib/kubelet/kubeadm-flags.env
# This is a file that the user can use for overrides of the kubelet args as a last resort. Preferably, the user should use
# the .NodeRegistration.KubeletExtraArgs object in the configuration files instead. KUBELET_EXTRA_ARGS should be sourced from this file.
EnvironmentFile=-/etc/sysconfig/kubelet
ExecStart=
ExecStart=/usr/bin/kubelet $KUBELET_KUBECONFIG_ARGS $KUBELET_CONFIG_ARGS $KUBELET_KUBEADM_ARGS $KUBELET_EXTRA_ARGS
[root@master001 kubelet.service.d]#

2.3 修改 kubelet 启动参数文件

  • /var/lib/kubelet/config.yaml
$ cd /var/lib/kubelet
$ ls -lrt
total 16
-rw-r--r--.  1 root root  146 Dec 30 19:09 kubeadm-flags.env
-rw-------.  1 root root   62 Dec 30 19:09 cpu_manager_state
drwx------.  2 root root    6 Dec 30 19:09 plugin-containers
drwxr-x---.  2 root root    6 Dec 30 19:09 plugins_registry
drwxr-x---.  2 root root    6 Dec 30 19:09 plugins
drwxr-xr-x.  2 root root  170 Dec 30 19:10 pki
-rw-r--r--.  1 root root 1774 Dec 31 15:32 config.yaml
drwxr-x---.  2 root root   26 Jan  8 13:48 pod-resources
drwxr-xr-x.  2 root root   80 Jan  8 14:12 device-plugins
drwxr-x---. 12 root root 4096 Jan  8 14:12 pods
$ vi /var/lib/kubelet/config.yaml

3. (方法二) 查找 kubelet 的启动配置文件

参数说明

  • –config=/var/lib/kubelet/config.yaml # 启动时的配置参数
  • –network-plugin=cni # 使用的网络插件
$ ps -ef | grep kubelet                  查看全部的 kubelet 启动时设置的参数
$ ps -ef | grep kubelet | grep config	 查看 kubelet 的配置文件位置

root      54019      1  2 Jan08 ?        1-07:36:24 /usr/bin/kubelet 
--bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf 
--kubeconfig=/etc/kubernetes/kubelet.conf 
--config=/var/lib/kubelet/config.yaml 		
--cgroup-driver=systemd 
--network-plugin=cni 
--pod-infra-container-image=registry.aliyuncs.com/google_containers/pause:3.1

4. 使对 kubelet 的修改生效


启动kubelet :systemctl start kubelet

停止kubelet:systemctl stop kubelet

重新载入systemd:systemctl daemon-reload

5. 再次查看kubelet启动参数

$ ps -ef | grep kubelet 

root      12372 126673  0 10:54 pts/0    00:00:00 grep --color=auto kubelet
root      20407  20372  2 Jan06 ?        1-03:24:04 kube-apiserver --advertise-address=164.52.43.131 --allow-privileged=true --authorization-mode=Node,RBAC --client-ca-file=/etc/kubernetes/pki/ca.crt --enable-admission-plugins=NodeRestriction --enable-bootstrap-token-auth=true --etcd-cafile=/etc/kubernetes/pki/etcd/ca.crt --etcd-certfile=/etc/kubernetes/pki/apiserver-etcd-client.crt --etcd-keyfile=/etc/kubernetes/pki/apiserver-etcd-client.key --etcd-servers=https://127.0.0.1:2379 --insecure-port=0 --kubelet-client-certificate=/etc/kubernetes/pki/apiserver-kubelet-client.crt --kubelet-client-key=/etc/kubernetes/pki/apiserver-kubelet-client.key --kubelet-preferred-address-types=InternalIP,ExternalIP,Hostname --proxy-client-cert-file=/etc/kubernetes/pki/front-proxy-client.crt --proxy-client-key-file=/etc/kubernetes/pki/front-proxy-client.key --requestheader-allowed-names=front-proxy-client --requestheader-client-ca-file=/etc/kubernetes/pki/front-proxy-ca.crt --requestheader-extra-headers-prefix=X-Remote-Extra- --requestheader-group-headers=X-Remote-Group --requestheader-username-headers=X-Remote-User --secure-port=6443 --service-account-key-file=/etc/kubernetes/pki/sa.pub --service-cluster-ip-range=10.96.0.0/12 --tls-cert-file=/etc/kubernetes/pki/apiserver.crt --tls-private-key-file=/etc/kubernetes/pki/apiserver.key

root      54019      1  2 Jan08 ?        1-07:34:58 /usr/bin/kubelet --bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --kubeconfig=/etc/kubernetes/kubelet.conf --config=/var/lib/kubelet/config.yaml --cgroup-driver=systemd --network-plugin=cni --pod-infra-container-image=registry.aliyuncs.com/google_containers/pause:3.1

你可能感兴趣的:(Kubernetes)