微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Kubernetes python 客户端脚本在 50 秒后返回错误

如何解决Kubernetes python 客户端脚本在 50 秒后返回错误

我使用 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 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?