k8s events如何显示标准时间

1.问题本质

kubectl get events 默认输出的时间字段(如 AGE)是相对时间(例如 5m, 2h),并非精确时间戳。这对排障(特别是多节点/跨组件事件链路)不够精确。要获取绝对时间(精确时间戳),需要切换输出格式或字段。


2.使用 -o custom-columns(推荐:结构化输出)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
kubectl get events \
-o custom-columns=\
TIME:.metadata.creationTimestamp,\
TYPE:.type,\
REASON:.reason,\
OBJECT:.involvedObject.name,\
MESSAGE:.message

kubectl get events \
--sort-by=.metadata.creationTimestamp \
-o custom-columns=\
TIME:.metadata.creationTimestamp,\
TYPE:.type,\
REASON:.reason,\
OBJ:.involvedObject.kind,\
NAME:.involvedObject.name,\
MSG:.message

输出示例:

1
2
TIME                         TYPE     REASON    OBJECT     MESSAGE
2026-04-23T02:30:12Z Normal Scheduled pod-xxx Successfully assigned

优点:

  • 直接得到精确时间
  • 可控字段,适合 SRE 排障。