> For the complete documentation index, see [llms.txt](https://imarslo.gitbook.io/book/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://imarslo.gitbook.io/book/virtualization/kubernetes/kubelet.md).

# kubelet

* [configuration files](#configuration-files)
  * [systemd](#systemd)
  * [kubelet](#kubelet)
  * [modfiy `/var/lib/kubelet`](#modfiy-varlibkubelet)
* [kuabelet configration](#kuabelet-configration)
  * [change kubelet root dir](#change-kubelet-root-dir)
* [config files](#config-files)
  * [`/etc/systemd/system/kubelet.service.d/10-kubeadm.conf`](#etcsystemdsystemkubeletserviced10-kubeadmconf)

{% hint style="info" %}
references:

> * [The kubelet drop-in file for systemd](https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/kubelet-integration/#the-kubelet-drop-in-file-for-systemd)
> * [Kubelet Configuration (v1beta1)](https://kubernetes.io/docs/reference/config-api/kubelet-config.v1beta1/)
> * [\* Install and Set Up kubectl on Linux](https://kubernetes.io/docs/tasks/tools/install-kubectl-linux/)
> * [how to change kubelet working dir to somewhere else](https://stackoverflow.com/a/53228571/2940319)
> * [Reconfiguring Kubelet in a live cluster](https://www.ibm.com/docs/en/cloud-private/3.2.x?topic=administration-reconfiguring-kubelet-in-live-cluster)
>   {% endhint %}

### [configuration files](https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/kubelet-integration/)

#### systemd

* service configure :
  * v1.12.3: `/etc/systemd/system/kubelet.service.d/10-kubeadm.conf`
  * v1.9.16: `/usr/lib/systemd/system/kubelet.service.d/10-kubeadm.conf`
  * check via:

    ```bash
    $ sudo systemctl status kubelet.service
    ● kubelet.service - kubelet: The Kubernetes Node Agent
       Loaded: loaded (/usr/local/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 Fri 2023-06-23 17:04:07 PDT; 7min ago
    ```
* environment file : `/etc/sysconfig/kubelet`

#### kubelet

* kubeconfig, kubelet configuration file :
  * `/etc/kubernetes/kubelet.conf`
* kubeConfig file to use for the TLS Bootstrap, (it is only used if `/etc/kubernetes/kubelet.conf` does not exist):
  * `/etc/kubernetes/bootstrap-kubelet.conf`
* file containing the kubelet's ComponentConfig, workflow in `kubelet init` :
  * `/var/lib/kubelet/config.yaml`
* dynamic environment file that contains `KUBELET_KUBEADM_ARGS` :
  * `/var/lib/kubelet/kubeadm-flags.env`
* user-specified flag overrides with `KUBELET_EXTRA_ARGS` :
  * `/etc/default/kubelet` (for DEBs)
  * `/etc/sysconfig/kubelet` (for RPMs)

#### modfiy `/var/lib/kubelet`

* [`KUBELET_EXTRA_ARGS`](https://stackoverflow.com/a/53228571/2940319)

  ```bash
  $ sudo systemctl stop kubelet
  $ sudo echo 'KUBELET_EXTRA_ARGS=--root-dir=/mnt/kubelet' > /etc/sysconfig/kubelet
  $ sudo systemctl daemon-reload
  $ sudo systemctl start kubelet
  ```

### kuabelet configration

> \[!TIP] references:<br>
>
> * [kubelet flag](https://kubernetes.io/docs/reference/command-line-tools-reference/kubelet/)
>   * `--root-dir` string Default: `/var/lib/kubelet`

#### [change kubelet root dir](https://stackoverflow.com/a/53228571/2940319)

```bash
$ cat /etc/sysconfig/kubelet
KUBELET_EXTRA_ARGS=--root-dir=/path/to/extra/folder

$ grep EnvironmentFile /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
EnvironmentFile=-/var/lib/kubelet/kubeadm-flags.env
EnvironmentFile=-/etc/sysconfig/kubelet

$ systemctl daemon-reload
$ systemctl enable kubelet --now
$ systemctl start kubelet
```

* because of

  ```bash
  $ grep '/etc/sysconfig/kubelet' /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
  EnvironmentFile=-/etc/sysconfig/kubele

  $ ps auxfww | grep kubelet
  root        2262  2.5  0.0 6830176 143332 ?      Ssl  13:01   2:26 /usr/bin/kubelet --bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --kubeconfig=/etc/kubernetes/kubelet.conf --config=/var/lib/kubelet/config.yaml --cgroup-driver=cgroupfs --network-plugin=cni --root-dir=/home/kubelet
  ```
* or [symolic link](https://stackoverflow.com/a/57872504/2940319)

  ```bash
  $ sudo systemctl stop kubelet
  $ mkdir -p /mnt/kubelet
  $ sudo cp -r /var/lib/kubelet/* /mnt/kubelet/
  $ sudo mv /var/lib/kubelet{,.backup}
  $ sudo ln -sf /mnt/kueblet /var/lib/kubelet
  $ sudo systemctl daemon-reload
  $ sudo systemctl start kubelet
  ```
* [or add `KUBELET_EXTRA_ARGS`](https://stackoverflow.com/a/46065250/2940319) :

  ```bash
  $ cat /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
  ...
  Environment="KUBELET_EXTRA_ARGS=$KUBELET_EXTRA_ARGS --root-dir=/path/to/extra/folder"
  ...
  ```

### config files

#### `/etc/systemd/system/kubelet.service.d/10-kubeadm.conf`

> \[!TIP] This file specifies the default locations for all of the files managed by kubeadm for the kubelet.
>
> * The KubeConfig file to use for the TLS Bootstrap is `/etc/kubernetes/bootstrap-kubelet.conf`, but it is only used if `/etc/kubernetes/kubelet.conf` does not exist.
> * The KubeConfig file with the unique kubelet identity is `/etc/kubernetes/kubelet.conf`.
> * The file containing the kubelet's ComponentConfig is `/var/lib/kubelet/config.yaml`.
> * The dynamic environment file that contains `KUBELET_KUBEADM_ARGS` is sourced from `/var/lib/kubelet/kubeadm-flags.env`.
> * The file that can contain user-specified flag overrides with `KUBELET_EXTRA_ARGS` is sourced from `/etc/default/kubelet` (for DEBs), or `/etc/sysconfig/kubelet` (for RPMs). `KUBELET_EXTRA_ARGS` is last in the flag chain and has the highest priority in the event of conflicting settings.

```bash
$ cat /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
# 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
```
