【问题标题】:How can I determine the current ephemeral-storage usage of a running Kubernetes pod?如何确定正在运行的 Kubernetes pod 的当前临时存储使用情况?
【发布时间】:2019-04-12 12:31:06
【问题描述】:

我如何通过 kubectl 判断 pod 当前使用了多少 ephemeral storage

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

resources:
  requests:
    memory: "60Mi"
    cpu: "70m"
    ephemeral-storage: "2Gi"
  limits:
    memory: "65Mi"
    cpu: "75m"
    ephemeral-storage: "4Gi"

但是,为了对临时存储设置良好的请求和限制,我需要知道这个值对于正在运行的 pod 的实际含义,我无法弄清楚。我可以使用kubectl top pod 获取 CPU 和内存使用情况,但据我所知,ephemeral storage usage is only actually calculated when making an actual eviction decision

【问题讨论】:

    标签: kubernetes kubectl disk-access


    【解决方案1】:

    纯粹的原始方法是使用disk usage (du) Unix 命令行。

    shell 到你的 pod:

    $ kubectl exec -it <pod-id> sh
    

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

    $ mount # check mount points if you'd like
    $ cd /mnt/of/ephemeral
    $ du .
    

    如果您不使用卷挂载:

    $ du .
    

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

    • cAdvisor 也嵌入到 kubelet 代码中,暴露在 /stats/summary/metrics 端点下。更多信息here。示例输出:

      $ 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
          }
      ...
      }
      

      同样:

      $ 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
      ...
      

      关于kubelet authentication/authorization的更多信息。

    • Prometheus

    更多关于 K8s 指标的信息here

    【讨论】:

    • “将目录更改为临时存储的挂载点”——应该看哪一个? overlay?
    • 这取决于您在 pod 规范中定义的挂载点
    • 但是我没有任何挂载点。临时存储包括所有容器日志等使用的存储。因此,使用“mount”命令的那部分答案并不完全正确。
    • 临时存储还包括容器日志和容器映像。
    猜你喜欢
    • 2020-03-21
    • 2021-06-29
    • 2021-12-25
    • 2019-10-09
    • 2020-11-12
    • 1970-01-01
    • 1970-01-01
    • 2019-03-16
    • 1970-01-01
    相关资源
    最近更新 更多