Skip to content

kubernetes.client.rest.ApiException: (503) error with list_cluster_custom_object #1173

@moluzhui

Description

@moluzhui

What happened (please include outputs or screenshots):
I wanted to use client to get node data collected by metric-server and set it to be collected every 30 seconds, but the following error occurred after several times of collection

Error is as follows

Exception in thread Thread-2:
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/threading.py", line 916, in _bootstrap_inner
    self.run()
  File "/usr/local/lib/python3.6/threading.py", line 864, in run
    self._target(*self._args, **self._kwargs)
  File "/test.py", line 51, in get_host_info
    for device_resource_info in api.list_cluster_custom_object("metrics.k8s.io", "v1beta1", "nodes")['items']:
  File "/usr/local/lib/python3.6/site-packages/kubernetes/client/api/custom_objects_api.py", line 1344, in list_cluster_custom_object
    (data) = self.list_cluster_custom_object_with_http_info(group, version, plural, **kwargs)  # noqa: E501
  File "/usr/local/lib/python3.6/site-packages/kubernetes/client/api/custom_objects_api.py", line 1457, in list_cluster_custom_object_with_http_info
    collection_formats=collection_formats)
  File "/usr/local/lib/python3.6/site-packages/kubernetes/client/api_client.py", line 345, in call_api
    _preload_content, _request_timeout)
  File "/usr/local/lib/python3.6/site-packages/kubernetes/client/api_client.py", line 176, in __call_api
    _request_timeout=_request_timeout)
  File "/usr/local/lib/python3.6/site-packages/kubernetes/client/api_client.py", line 366, in request
    headers=headers)
  File "/usr/local/lib/python3.6/site-packages/kubernetes/client/rest.py", line 241, in GET
    query_params=query_params)
  File "/usr/local/lib/python3.6/site-packages/kubernetes/client/rest.py", line 231, in request
    raise ApiException(http_resp=r)
kubernetes.client.rest.ApiException: (503)
Reason: Service Unavailable
HTTP response headers: HTTPHeaderDict({'Content-Type': 'text/plain; charset=utf-8', 'X-Content-Type-Options': 'nosniff', 'Date': 'Wed, 27 May 2020 14:03:55 GMT', 'Content-Length': '20'})
HTTP response body: service unavailable

What you expected to happen:
I want to be able to get node's resource status every time.

How to reproduce it (as minimally and precisely as possible):
The client part of the code is as follows

config.kube_config.load_kube_config(config_file="~/.kube/config")
v1 = client.CoreV1Api()
api = client.CustomObjectsApi()
while(true):
    for node_resource_info in api.list_cluster_custom_object("metrics.k8s.io", "v1beta1", "nodes")['items']:
    ...
    ...
    time.sleep(30)

Anything else we need to know?:

Environment:

  • Kubernetes version (kubectl version): v1.17.3
  • OS (e.g., MacOS 10.13.6): The container OS is Alpine Linux 3.10 and the host OS is Ubuntu 16.04.6 LTS
  • Python version (python --version): python3.6.9
  • Python client version (pip list | grep kubernetes):kubernetes==11.0.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    lifecycle/staleDenotes an issue or PR has remained open with no activity and has become stale.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions