【问题标题】:Python Kubernetes client equivalent of kubectl describe pod | grep EventsPython Kubernetes 客户端等效于 kubectl describe pod | grep 事件
【发布时间】:2020-07-18 14:24:25
【问题描述】:

我正在为 AWS 上的自托管 kubernetes 集群创建自定义监控脚本。在所有其他工具中,我对 Python 客户端非常感兴趣。我有一本关于 pod 及其状态的字典。现在我想迭代 dict.keys(基本上是其中的 pod)以从 kubelet 检查他们的事件。我正在寻找以下数据:

Events:
  Type     Reason       Age                    From                                                  Message
  ----     ------       ----                   ----                                                  -------
  Warning  FailedMount  20m (x25188 over 44d)  kubelet, ip-10-222-145-32.us-west-2.compute.internal  MountVolume.SetUp failed for volume "sag-license-volume" : configmap "my-licence" not found
  Warning  FailedMount  35s (x72078 over 44d)  kubelet, ip-10-222-155-32.us-west-2.compute.internal  (combined from similar events): MountVolume.SetUp failed for volume "my-license-volume" : configmap "my-license" not found

我浏览了网络,只能找到与命名空间相关的示例,而不是与单个 pod 相关的示例。

请帮助我通过 Python 客户端获取这些数据。提前致谢!

【问题讨论】:

    标签: python kubernetes kubernetes-python-client


    【解决方案1】:

    字段选择器成功了,使用 list_namespaced_event 解决了这个问题。

    field_selector='involvedObject.name='+'my_pod'
    stream = watch.Watch().stream(v1.list_namespaced_event, "my_ns", field_selector=field_selector, timeout_seconds=1)
    for event in stream:
        print(event['object'].message)
    

    【讨论】:

      猜你喜欢
      • 2021-05-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-02
      • 2019-11-06
      • 2015-09-11
      • 2020-06-14
      相关资源
      最近更新 更多