尝试使用python kubernetes API来流化kubernetes pod日志的输出。 (最终目标是通过websocket流式传输日志)
基于此PR(已合并到python kubernetes模块中),我认为手表可以与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)
但是我收到下面的错误,我是否缺少需要传递的内容?还是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
答案 0 :(得分:4)
您应该这样做:
v1 = client.CoreV1Api()
w = Watch()
for e in w.stream(v1.read_namespaced_pod_log, name=pod, namespace=namespace):
print(e)