Kubelet 使用什么来确定节点的临时存储容量?

What does Kubelet use to determine the ephemeral-storage capacity of the node?

我在 VM 上有 Kubernetes 集群 运行。坐骑的截断概述是:

$ df -h
Filesystem                    Size  Used Avail Use% Mounted on
/dev/sda1                      20G  4.5G   15G  24% /
/dev/mapper/vg001-lv--docker  140G   33G  108G  23% /var/lib/docker

如您所见,我添加了一个额外的磁盘来存储 docker 图像及其卷。但是查询节点容量时,返回如下

Capacity:
  cpu:                12
  ephemeral-storage:  20145724Ki
  hugepages-1Gi:      0
  hugepages-2Mi:      0
  memory:             65831264Ki
  nvidia.com/gpu:     1
  pods:               110

ephemeral-storage20145724Ki也就是20G,指的是挂载在/的磁盘。

Kubelet 是如何计算它的 ephemeral-storage 的?它只是查看 / 上可用的磁盘 space 吗?或者它正在查看另一个文件夹,例如 /var/log/containers?

用户最终屈服于增加安装在 / 的磁盘。

一些理论

默认情况下,标准 kubernetes 环境中 ephemeral-storage 的 CapacityAllocatable 来自文件系统(安装到 /var/lib/kubelet)。 这是 kubelet 目录的默认位置。

The kubelet supports the following filesystem partitions:

  1. nodefs: The node's main filesystem, used for local disk volumes, emptyDir, log storage, and more. For example, nodefs contains /var/lib/kubelet/.
  2. imagefs: An optional filesystem that container runtimes use to store container images and container writable layers.

Kubelet auto-discovers these filesystems and ignores other filesystems. Kubelet does not support other configurations.

来自 Kubernetes website 关于卷:

The storage media (such as Disk or SSD) of an emptyDir volume is determined by the medium of the filesystem holding the kubelet root dir (typically /var/lib/kubelet).

可以通过提供以下内容来配置 kubelet 目录的位置:

  1. Command line parameter during kubelet initialization

--root-dir 字符串 默认值:/var/lib/kubelet

  1. 通过 kubeadm with config file(例如)
apiVersion: kubeadm.k8s.io/v1beta3
kind: InitConfiguration
nodeRegistration:
  kubeletExtraArgs:
    root-dir: "/data/var/lib/kubelet"

Customizing kubelet:

To customize the kubelet you can add a KubeletConfiguration next to the ClusterConfiguration or InitConfiguration separated by --- within the same configuration file. This file can then be passed to kubeadm init.

当使用 kubeadm 引导 kubernetes 集群时,kubectl get node 报告的 Capacity 等于安装到 /var/lib/kubelet

的磁盘容量

然而 Allocatable 将被报告为: Allocatable = Capacity - 10% nodefs 使用标准的 kubeadm 配置,因为 the kubelet has the following default hard eviction thresholds:

  • nodefs.available<10%

可以在 kubelet initialization 期间配置: -eviction-hard mapStringString 默认值:imagefs.available<15%,memory.available<100Mi,nodefs.available<10%


例子

我用一个主节点和两个工作节点(worker-1 和 worker-2)为 Kubernetes 设置了一个测试环境。

两个工作节点都有相同容量的卷:50Gb。

另外,我在路径/var/lib/kubelet上为Worker-1节点挂载了容量为20Gb的第二卷。 然后我用 kubeadm 创建了一个集群。

结果

来自 worker-1 节点:

skorkin@worker-1:~# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1        49G  2.8G   46G   6% /
...
/dev/sdb         20G   45M   20G   1% /var/lib/kubelet

Capacity:
  cpu:                2
  ephemeral-storage:  20511312Ki
  hugepages-1Gi:      0
  hugepages-2Mi:      0
  memory:             4027428Ki
  pods:               110

ephemeral-storage 的大小与安装在 /var/lib/kubelet 的卷相同。

来自 worker-2 节点:

skorkin@worker-2:~# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1        49G  2.7G   46G   6% /

Capacity:
  cpu:                2
  ephemeral-storage:  50633164Ki
  hugepages-1Gi:      0
  hugepages-2Mi:      0
  memory:             4027420Ki
  pods:               110