问题描述
我使用 python 客户端制作了自定义的 K8s 调度程序。这是在没有分配节点的情况下监视 Pod 的代码的一部分。
def main():
w = watch.Watch()
for event in w.stream(v1.list_namespaced_pod,"default"):
if event['type'] == "ADDED" and event['object'].status.phase == "Pending" and event['object'].spec.scheduler_name == schedulerName:
try:
nodes=get_nodes()
print(nodes)
res = scheduler(event['object'].Metadata.name,select_node(nodes))
print("Node %s is chosen for pod %s" % (select_node(nodes),event['object'].Metadata.name))
except client.rest.ApiException as e:
print (e)
除了事件中没有任何活动 50 秒后没有其他错误,脚本崩溃并出现以下错误
Traceback (most recent call last):
File "/usr/local/lib/python3.7/dist-packages/urllib3/response.py",line 697,in _update_chunk_length
self.chunk_left = int(line,16)
ValueError: invalid literal for int() with base 16: b''
During handling of the above exception,another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/dist-packages/urllib3/response.py",line 438,in _error_catcher
yield
File "/usr/local/lib/python3.7/dist-packages/urllib3/response.py",line 764,in read_chunked
self._update_chunk_length()
File "/usr/local/lib/python3.7/dist-packages/urllib3/response.py",line 701,in _update_chunk_length
raise InvalidChunkLength(self,line)
urllib3.exceptions.InvalidChunkLength: InvalidChunkLength(got length b'',0 bytes read)
During handling of the above exception,another exception occurred:
Traceback (most recent call last):
File "scheduler.py",line 77,in <module>
main()
File "scheduler.py",line 65,in main
for event in w.stream(v1.list_namespaced_pod,"default"):
File "/usr/local/lib/python3.7/dist-packages/kubernetes/watch/watch.py",line 117,in stream
for line in iter_resp_lines(resp):
File "/usr/local/lib/python3.7/dist-packages/kubernetes/watch/watch.py",line 45,in iter_resp_lines
for seg in resp.read_chunked(decode_content=False):
File "/usr/local/lib/python3.7/dist-packages/urllib3/response.py",line 793,in read_chunked
self._original_response.close()
File "/usr/lib/python3.7/contextlib.py",line 130,in __exit__
self.gen.throw(type,value,traceback)
File "/usr/local/lib/python3.7/dist-packages/urllib3/response.py",line 455,in _error_catcher
raise ProtocolError("Connection broken: %r" % e,e)
urllib3.exceptions.ProtocolError: ("Connection broken: InvalidChunkLength(got length b'',0 bytes read)",InvalidChunkLength(got length b'',0 bytes read))
我使用 Kubernetes v1.20,在它们前面有多个 master 和 HAProxy。我使用的 K8s 的 Python 模块是 2.0.0。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)