如何确定正在运行的Kubernetes Pod的当前临时存储使用情况?

bsk*_*ggs 5 diskusage kubernetes kubectl

我如何知道豆荚当前使用kubectl了多少临时存储

在Kubernetes pod规范中,我可以指定资源请求以及CPU,内存和临时存储的限制:

resources:
  requests:
    memory: "60Mi"
    cpu: "70m"
    ephemeral-storage: "2Gi"
  limits:
    memory: "65Mi"
    cpu: "75m"
    ephemeral-storage: "4Gi"
Run Code Online (Sandbox Code Playgroud)

但是,为了对临时存储设置良好的请求和限制,我需要知道此值对于正在运行的Pod实际上是什么,我不知道。我可以使用获得CPU和内存使用率kubectl top pod,但是据我所知,临时存储使用率仅在做出实际驱逐决策时才实际计算得出

son*_*207 20

您可以通过 raw 命令来完成此操作。

kubectl get --raw "/api/v1/nodes/(your-node-name)/proxy/stats/summary"

还有这个

kubectl get --raw "/api/v1/nodes/(your-node-name)/proxy/metrics/cadvisor""

编辑:

我现在为此创建了一个 Prometheus 导出器。

https://github.com/jmcgrath207/k8s-ephemeral-storage-metrics

  • 要按名称选择单个 pod,您可以将该命令的输出通过管道传输到 `jq '.pods[] | select(.podRef.name == "mypodname")'` (2认同)

Ric*_*ico 9

纯粹的原始方法是使用磁盘使用情况(du) Unix 命令行。

进入你的 pod 中:

$ kubectl exec -it <pod-id> sh
Run Code Online (Sandbox Code Playgroud)

将目录更改为临时存储的挂载点(如果您使用的是卷挂载):

$ mount # check mount points if you'd like
$ cd /mnt/of/ephemeral
$ du .
Run Code Online (Sandbox Code Playgroud)

如果您不使用卷安装:

$ du .
Run Code Online (Sandbox Code Playgroud)

您还可以使用其他工具来获取指标:

  • cAdvisor还嵌入到 kubelet 代码中,在/stats/summary/metrics端点下公开。更多信息请点击这里。输出示例:

    $ curl -k -H 'Authorization: Bearer <Redacted>' \
    https://node-hostname:10250/stats/summary
    
    {
     "node": {
       "nodeName": "node-hostname",
       "systemContainers": [
        {
         "name": "kubelet",
        ...
        "volume": [
         {
          "time": "2018-11-08T23:52:03Z",
          "availableBytes": 1969168384,
          "capacityBytes": 1969180672,
          "usedBytes": 12288,
          "inodesFree": 480748,
          "inodes": 480757,
          "inodesUsed": 9,
          "name": "kube-proxy-token-pprwb"
         }
        ],
        "ephemeral-storage": {
         "time": "2018-11-09T00:05:10Z",
         "availableBytes": 31057477632,
         "capacityBytes": 41567858688,
         "inodesFree": 4873887,
         "inodes": 5120000
        }
    ...
    }
    
    Run Code Online (Sandbox Code Playgroud)

    相似地:

    $ curl -k -H 'Authorization: Bearer <Redacted>' \
    https://node-hostname:10250/stats/summary
    
    # HELP apiserver_audit_event_total Counter of audit events generated and sent to the audit backend.
    # TYPE apiserver_audit_event_total counter
    apiserver_audit_event_total 0
    # HELP apiserver_client_certificate_expiration_seconds Distribution of the remaining lifetime on the certificate used to authenticate a request.
    # TYPE apiserver_client_certificate_expiration_seconds histogram
    apiserver_client_certificate_expiration_seconds_bucket{le="0"} 0
    apiserver_client_certificate_expiration_seconds_bucket{le="21600"} 0
    apiserver_client_certificate_expiration_seconds_bucket{le="43200"} 0
    ...
    
    Run Code Online (Sandbox Code Playgroud)

    有关kubelet 身份验证/授权的更多信息。

  • 普罗米修斯

有关 K8s 指标的更多信息请参见此处

  • 但我没有任何挂载点。临时存储包括所有容器日志等使用的存储。因此,“mount”命令在该部分的答案并不完全正确。 (7认同)
  • 临时存储还包括容器日志和容器镜像。 (3认同)