【问题标题】:Can kubectl describe show timestamp of pod events?kubectl 可以描述显示 pod 事件的时间戳吗?
【发布时间】:2017-03-01 03:30:21
【问题描述】:

Kubectl describe pods 输出自 pod 事件发生以来经过的时间;例如

kubectl describe pods my-pod

输出

Events:
  FirstSeen     LastSeen        Count   From                                                        SubobjectPath                           TypeReason           Message
  ---------     --------        -----   ----                                                            -------------                           --------     ------          -------
  21s           21s             1       {default-scheduler }                                                                                    Normal               Scheduled       Successfully assigned xlxqh to gf959ad9f-cwvs
  19s           19s             1       {kubelet f959ad9f-cwvs}       spec.containers{gpu-sample-devices}     Normal               Pulling         pulling image "b.gcr.io/foo/sample:latest"

是否可以让 kubectl describe 输出事件的实际时间?

【问题讨论】:

    标签: kubernetes google-kubernetes-engine


    【解决方案1】:

    tl;博士; kubectl 不允许 describe 用于事件,也不提供查看每个事件发生的时间戳的方法。


    kubectl 不提供每次事件发生的时间戳。如果事件发生了一次,它将显示自看到事件以来经过的时间。如果有多次出现,它只会显示自第一次出现以来的时间,以及自最近一次出现以来的时间。

    假设:我在 Kubernetes repo 中找不到表明其背后的设计目标的设计问题,但我会假设如下:集群中的节点可能存在于多个时区,您可能从与集群完全不同的时区访问 API。因此,显示经过的时间往往比时间戳更能指示问题发生的时间

    【讨论】:

    • 对不起,我的问题不恰当。我的意思是当你做 kubectl describe pods 时,输出的事件已经过去了,而不是实际的时间戳。
    【解决方案2】:

    如果您使用kubectl get events,您可以。如果您尝试查看事件时间戳,可以请求 yaml/json 格式的输出。请注意,对于每个事件,它仍然只会为您提供 firstTimestamplastTimestamp

    例如,

    kubectl 获取事件 -o yaml

    - apiVersion: v1
      count: 1
      firstTimestamp: 2016-10-19T23:02:47Z
      involvedObject:
        kind: Node
        name: xyz
        uid: 1e8f04e8-9650-11e6-b1ec-42010af00002
      kind: Event
      lastTimestamp: 2016-10-19T23:02:47Z
      message: 'Node xyz event: Registered Node xyz
        in NodeController'
      metadata:
        creationTimestamp: 2016-10-19T23:02:47Z
        name: xyz
        namespace: default
        resourceVersion: "192"
        selfLink: /api/v1/namespaces/default/events/xyz.147f113f8a7c7a80
        uid: 26d053b6-9650-11e6-b1ec-42010af00002
      reason: RegisteredNode
      source:
        component: controllermanager
      type: Normal
    

    这将为Event 类型的原始资源提供时间戳。然后,您可以缩小您感兴趣的活动范围。

    【讨论】:

      【解决方案3】:

      您可以在event objects 上使用custom columnsfields selector(由 kubectl 提供)的组合。示例:

      $ kubectl get events -o custom-columns=FirstSeen:.firstTimestamp,LastSeen:.lastTimestamp,Count:.count,From:.source.component,Type:.type,Reason:.reason,Message:.message \
                           --field-selector involvedObject.kind=Pod,involvedObject.name=my-pod
      FirstSeen              LastSeen               Count   From                Type      Reason             Message
      2020-01-21T16:30:25Z   2020-01-21T16:30:25Z   1       default-scheduler   Normal    Scheduled          Successfully assigned my-pod to 10.10.1.3
      2020-01-21T16:30:26Z   2020-01-21T16:30:26Z   1       kubelet             Normal    Pulling            Pulling image "my-image"
      2020-01-21T16:30:26Z   2020-01-21T16:30:26Z   1       kubelet             Normal    Pulled             Successfully pulled image "my-image"
      2020-01-21T16:30:26Z   2020-01-21T16:30:26Z   1       kubelet             Normal    Created            Created container my-container
      2020-01-21T16:30:27Z   2020-01-21T16:30:27Z   1       kubelet             Normal    Started            Started container my-container
      
      

      【讨论】:

        【解决方案4】:

        您可以查看 pod lastTransitionTime 的类型:Ready

        kubectl get po <my-pod> -o json | jq -r '.status.conditions'
        [
          {
            "lastProbeTime": null,
            "lastTransitionTime": "2021-08-10T10:47:25Z",
            "status": "True",
            "type": "Initialized"
          },
          {
            "lastProbeTime": null,
            "lastTransitionTime": "2021-08-10T10:48:00Z",
            "status": "True",
            "type": "Ready"
          },
          {
            "lastProbeTime": null,
            "lastTransitionTime": "2021-08-10T10:48:00Z",
            "status": "True",
            "type": "ContainersReady"
          },
          {
            "lastProbeTime": null,
            "lastTransitionTime": "2021-08-10T10:47:25Z",
            "status": "True",
            "type": "PodScheduled"
          }
        ]
        

        官方链接:https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2017-12-22
          • 2019-01-26
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多