Kubernetes 临时存储限制和容器日志
Kubernetes Ephemeral Storage Limit and Container Logs
假设我已经为 Kubernetes 集群中的容器设置了 resource.limits.ephemeral-storage
(使用 Docker),并且在工作节点上设置了以下 Docker daemon.json 日志记录配置:
{
"log-driver": "json-file",
"log-opts": {
"max-size": "100m",
"max-file": "10",
}
}
我的理解是所有日志文件(甚至轮换的日志文件)都将计入此临时存储限制。这意味着要确定 resource.limits.ephemeral-storage
的值,我必须在计算中考虑允许的最大日志大小(此处为 10*100MB)。
有没有办法“排除”日志文件计入容器的临时存储限制?
由于日志处理是在 Kubernetes 的“外部”完成的,我想避免 Kubernetes 工作负载的资源限制取决于 Docker 日志配置。否则,如果忘记调整每个容器的限制,对旋转设置的任何更改(例如增加到 10*200MB)都可能导致 pods 被驱逐。
基于函数 calcEphemeralStorage from release 1.17.16 source code,如果你想从计算中排除日志,你可以评论或删除这些行并重建 kubelet:
if podLogStats != nil {
result.UsedBytes = addUsage(result.UsedBytes, podLogStats.UsedBytes)
result.InodesUsed = addUsage(result.InodesUsed, podLogStats.InodesUsed)
result.Time = maxUpdateTime(&result.Time, &podLogStats.Time)
}
这部分代码负责计算日志的临时存储使用情况。但是删除那部分代码可能还需要调整一些期望计算日志量的测试文件。
所有统计数据都计入 this function:
func (p *criStatsProvider) makePodStorageStats(s *statsapi.PodStats, rootFsInfo *cadvisorapiv2.FsInfo) {
podNs := s.PodRef.Namespace
podName := s.PodRef.Name
podUID := types.UID(s.PodRef.UID)
vstats, found := p.resourceAnalyzer.GetPodVolumeStats(podUID)
if !found {
return
}
logStats, err := p.hostStatsProvider.getPodLogStats(podNs, podName, podUID, rootFsInfo)
if err != nil {
klog.ErrorS(err, "Unable to fetch pod log stats", "pod", klog.KRef(podNs, podName))
// If people do in-place upgrade, there might be pods still using
// the old log path. For those pods, no pod log stats is returned.
// We should continue generating other stats in that case.
// calcEphemeralStorage tolerants logStats == nil.
}
etcHostsStats, err := p.hostStatsProvider.getPodEtcHostsStats(podUID, rootFsInfo)
if err != nil {
klog.ErrorS(err, "Unable to fetch pod etc hosts stats", "pod", klog.KRef(podNs, podName))
}
ephemeralStats := make([]statsapi.VolumeStats, len(vstats.EphemeralVolumes))
copy(ephemeralStats, vstats.EphemeralVolumes)
s.VolumeStats = append(append([]statsapi.VolumeStats{}, vstats.EphemeralVolumes...), vstats.PersistentVolumes...)
s.EphemeralStorage = calcEphemeralStorage(s.Containers, ephemeralStats, rootFsInfo, logStats, etcHostsStats, true)
}
在最后一行你可以找到 calcEphemeralStorage
.
的用法
在最近的版本中 mentioned code include the same log calculation section, so the solution should work for the latest release 也是。
另请参阅:
假设我已经为 Kubernetes 集群中的容器设置了 resource.limits.ephemeral-storage
(使用 Docker),并且在工作节点上设置了以下 Docker daemon.json 日志记录配置:
{
"log-driver": "json-file",
"log-opts": {
"max-size": "100m",
"max-file": "10",
}
}
我的理解是所有日志文件(甚至轮换的日志文件)都将计入此临时存储限制。这意味着要确定 resource.limits.ephemeral-storage
的值,我必须在计算中考虑允许的最大日志大小(此处为 10*100MB)。
有没有办法“排除”日志文件计入容器的临时存储限制?
由于日志处理是在 Kubernetes 的“外部”完成的,我想避免 Kubernetes 工作负载的资源限制取决于 Docker 日志配置。否则,如果忘记调整每个容器的限制,对旋转设置的任何更改(例如增加到 10*200MB)都可能导致 pods 被驱逐。
基于函数 calcEphemeralStorage from release 1.17.16 source code,如果你想从计算中排除日志,你可以评论或删除这些行并重建 kubelet:
if podLogStats != nil {
result.UsedBytes = addUsage(result.UsedBytes, podLogStats.UsedBytes)
result.InodesUsed = addUsage(result.InodesUsed, podLogStats.InodesUsed)
result.Time = maxUpdateTime(&result.Time, &podLogStats.Time)
}
这部分代码负责计算日志的临时存储使用情况。但是删除那部分代码可能还需要调整一些期望计算日志量的测试文件。 所有统计数据都计入 this function:
func (p *criStatsProvider) makePodStorageStats(s *statsapi.PodStats, rootFsInfo *cadvisorapiv2.FsInfo) {
podNs := s.PodRef.Namespace
podName := s.PodRef.Name
podUID := types.UID(s.PodRef.UID)
vstats, found := p.resourceAnalyzer.GetPodVolumeStats(podUID)
if !found {
return
}
logStats, err := p.hostStatsProvider.getPodLogStats(podNs, podName, podUID, rootFsInfo)
if err != nil {
klog.ErrorS(err, "Unable to fetch pod log stats", "pod", klog.KRef(podNs, podName))
// If people do in-place upgrade, there might be pods still using
// the old log path. For those pods, no pod log stats is returned.
// We should continue generating other stats in that case.
// calcEphemeralStorage tolerants logStats == nil.
}
etcHostsStats, err := p.hostStatsProvider.getPodEtcHostsStats(podUID, rootFsInfo)
if err != nil {
klog.ErrorS(err, "Unable to fetch pod etc hosts stats", "pod", klog.KRef(podNs, podName))
}
ephemeralStats := make([]statsapi.VolumeStats, len(vstats.EphemeralVolumes))
copy(ephemeralStats, vstats.EphemeralVolumes)
s.VolumeStats = append(append([]statsapi.VolumeStats{}, vstats.EphemeralVolumes...), vstats.PersistentVolumes...)
s.EphemeralStorage = calcEphemeralStorage(s.Containers, ephemeralStats, rootFsInfo, logStats, etcHostsStats, true)
}
在最后一行你可以找到 calcEphemeralStorage
.
在最近的版本中 mentioned code include the same log calculation section, so the solution should work for the latest release 也是。
另请参阅: