Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Kubernetes client exception with connection refused error

Đang mở
#2,041 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 3 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Cần làm rõ
Mức độ hoạt động
Đình trệ
Công nghệ
kubernetes, python
Lĩnh vực
devops, infrastructure

Hướng nghiên cứu

Bắt đầu với hàm k8s_exec và đường dẫn websocket_call trong kubernetes/stream/ws_client.py, đặc biệt là lỗi được báo cáo ở dòng 525. Tái hiện lỗi kết nối bị từ chối xảy ra không liên tục trên các môi trường Kubernetes đã nêu và so sánh lỗi đó với issue 1841. Công việc được xem là hoàn tất khi xác định và xử lý được nguyên nhân để các kết nối websocket vẫn khả dụng trong khi thực hiện các lệnh gọi pod exec.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

help wanted help-needed kind/bug kind/support

Our tests had been running fine till we started running into the following issue where the kubernetes client websocket call will terminate with an exception:

channel = stream(api.connect_get_namespaced_pod_exec,

/usr/lib/python3.8/site-packages/kubernetes/stream/stream.py:35: in _websocket_request
return api_method(*args, **kwargs)
/usr/lib/python3.8/site-packages/kubernetes/client/api/core_v1_api.py:994: in connect_get_namespaced_pod_exec
return self.connect_get_namespaced_pod_exec_with_http_info(name, namespace, **kwargs) # noqa: E501
/usr/lib/python3.8/site-packages/kubernetes/client/api/core_v1_api.py:1101: in connect_get_namespaced_pod_exec_with_http_info
return self.api_client.call_api(
/usr/lib/python3.8/site-packages/kubernetes/client/api_client.py:348: in call_api
return self.__call_api(resource_path, method,
/usr/lib/python3.8/site-packages/kubernetes/client/api_client.py:180: in __call_api
response_data = self.request(


configuration = <kubernetes.client.configuration.Configuration object at 0x7f192844cb20>
_method = 'GET'
url = 'wss://api.ndal-ocp2.ve.pd.f5net.com:6443/api/v1/namespaces/spk-test-automation/pods/ans-client-ci6492742-127/exec?com...command=2001%3A0db8%3A0%3A127%3A%3A100&command=-t&command=10&command=-P8&stderr=True&stdin=False&stdout=True&tty=False'
kwargs = {'_preload_content': False, '_request_timeout': None, 'body': None, 'headers': {'Accept': '/', 'User-Agent': 'OpenAPI-Generator/25.3.0/python', 'authorization': 'Bearer sha256bgMewSf5E2EdW_h4EYLI4Ju-I21kPKVzK5tRTvqFgtg'}, ...}
headers = {'Accept': '/', 'User-Agent': 'OpenAPI-Generator/25.3.0/python', 'authorization': 'Bearer sha256
bgMewSf5E2EdW_h4EYLI4Ju-I21kPKVzK5tRTvqFgtg'}
_request_timeout = None, _preload_content = False, capture_all = True
def websocket_call(configuration, _method, url, **kwargs):
"""An internal function to be called in api-client when a websocket
connection is required. method, url, and kwargs are the parameters of
apiClient.request method."""

    url = get_websocket_url(url, kwargs.get("query_params"))
    headers = kwargs.get("headers")
    _request_timeout = kwargs.get("_request_timeout", 60)
    _preload_content = kwargs.get("_preload_content", True)
    capture_all = kwargs.get("capture_all", True)

    try:
        client = WSClient(configuration, url, headers, capture_all)
        if not _preload_content:
            return client
        client.run_forever(timeout=_request_timeout)
        return WSResponse('%s' % ''.join(client.read_all()))
    except (Exception, KeyboardInterrupt, SystemExit) as e:
      raise ApiException(status=0, reason=str(e))

E kubernetes.client.exceptions.ApiException: (0)
E Reason: [Errno 111] Connection refused
/usr/lib/python3.8/site-packages/kubernetes/stream/ws_client.py:525: ApiException

These exceptions happen at random (not for any specific or every test) and across different kubernetes environment/clusters. They started happening somewhere around early Feb, 2023. (not sure if its related to any fixes/changes).

Below is what we use in our code:
`def k8s_exec(command, pod, namespace, api):
channel = stream(api.connect_get_namespaced_pod_exec,
pod,
namespace,
command=command,
stderr=True, stdin=False,
stdout=True, tty=False,
_preload_content=False)
channel.run_forever(timeout=60)
err = yaml.safe_load(channel.read_channel(ERROR_CHANNEL))
if err is None:
raise AssertionError(f'The command "{command}" was timeouted')
rc = 0 if err['status'] == 'Success' else 1
stdout = channel.read_stdout()
stderr = channel.read_stderr()

return rc, stdout, stderr`

Not sure if this is similar to: 1841

What you expected to happen:
Connection is retained.

Environment:

  • Kubernetes version (kubectl version):
    Client Version: version.Info{Major:"1", Minor:"20"
    Server Version: version.Info{Major:"1", Minor:"23"
  • OS (e.g., MacOS 10.13.6): Linux
  • Python version (python --version): 2.7.5
Ngôn ngữ chính
Python
Star
7.7k
Fork
3.5k
Merge trung bình
3 ngày 4 giờ
Pull request đã merge (30 ngày)
9

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của kubernetes-client/python

Tất cả issue của kubernetes-client/python

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.