簡體   English   中英

Python Kubernetes 客戶端等效於 kubectl describe pod | grep 事件

[英]Python Kubernetes client equivalent of kubectl describe pod | grep Events

我正在為 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

我查看了 web 並且只能找到與命名空間相關的示例,但找不到與單個 pod 相關的示例。

請幫助我通過 Python 客戶端獲取這些數據。 提前致謝 !

字段選擇器成功了,使用 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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM