简体   繁体   English

python kubernetes观看pod日志不起作用

[英]python kubernetes watch pod logs not working

Trying to use the python kubernetes API to stream the output of kubernetes pod logs. 尝试使用python kubernetes API来流化kubernetes pod日志的输出。 (eventual goal is to stream the logs out via websocket) (最终目标是通过websocket传输日志)

Based off this PR that was merged into python kubernetes module, i thought watch would work with read_namespaced_pod_log? 基于已合并到python kubernetes模块中的PR ,我认为手表可以与read_namespaced_pod_log一起使用?

v1 = client.CoreV1Api()
w = watch.Watch()
for e in w.stream(v1.read_namespaced_pod_log, name=pod, namespace=namespace, follow=True, tail_lines=1, limit_bytes=560, _preload_content=False):
   print(e)

But i get the error below, am i missing something that needs to be passed to watch? 但是我收到以下错误,我是否错过了需要传递的内容? or read_namespaced_pod_log? 还是read_namespaced_pod_log?

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.7/site-packages/kubernetes/watch/watch.py", line 132, in stream
    resp = func(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/kubernetes/client/apis/core_v1_api.py", line 18538, in read_namespaced_pod_log
    (data) = self.read_namespaced_pod_log_with_http_info(name, namespace, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/kubernetes/client/apis/core_v1_api.py", line 18576, in read_namespaced_pod_log_with_http_info
    " to method read_namespaced_pod_log" % key
TypeError: Got an unexpected keyword argument 'watch' to method read_namespaced_pod_log

You should just do: 您应该这样做:

v1 = client.CoreV1Api()
w = Watch()
for e in w.stream(v1.read_namespaced_pod_log, name=pod, namespace=namespace):
    print(e)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM