尝试使用python客户端获取CRD时出现404 [英] 404 when trying to get CRD using python client

查看:204
本文介绍了尝试使用python客户端获取CRD时出现404的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

发生了什么

我正在尝试使用kubernetes python客户端在kubernetes中创建自定义对象,但是我无法这样做,如果有人可以在这里解释我做错的事情会很有帮助

I am trying to create custom object in kubernetes using kubernetes python client, but i am unable to do so, it would be helpful if someone can explain what i am doing wrong here

Traceback (most recent call last):
  File "/home/talha/PycharmProjects/doosra/tasks/cluster_tasks.py", line 585, in <module>
    main()
  File "/home/talha/PycharmProjects/doosra/tasks/cluster_tasks.py", line 574, in main
    resource = api.get_namespaced_custom_object(
  File "/home/talha/PycharmProjects/venv/lib/python3.8/site-packages/kubernetes/client/api/custom_objects_api.py", line 1484, in get_namespaced_custom_object
    return self.get_namespaced_custom_object_with_http_info(group, version, namespace, plural, name, **kwargs)  # noqa: E501
  File "/home/talha/PycharmProjects/venv/lib/python3.8/site-packages/kubernetes/client/api/custom_objects_api.py", line 1591, in get_namespaced_custom_object_with_http_info
    return self.api_client.call_api(
  File "/home/talha/PycharmProjects/venv/lib/python3.8/site-packages/kubernetes/client/api_client.py", line 348, in call_api
    return self.__call_api(resource_path, method,
  File "/home/talha/PycharmProjects/venv/lib/python3.8/site-packages/kubernetes/client/api_client.py", line 180, in __call_api
    response_data = self.request(
  File "/home/talha/PycharmProjects/venv/lib/python3.8/site-packages/kubernetes/client/api_client.py", line 373, in request
    return self.rest_client.GET(url,
  File "/home/talha/PycharmProjects/venv/lib/python3.8/site-packages/kubernetes/client/rest.py", line 239, in GET
    return self.request("GET", url,
  File "/home/talha/PycharmProjects/venv/lib/python3.8/site-packages/kubernetes/client/rest.py", line 233, in request
    raise ApiException(http_resp=r)
kubernetes.client.exceptions.ApiException: (404)
Reason: Not Found
HTTP response headers: HTTPHeaderDict({'Cache-Control': 'no-cache, private', 'Content-Type': 'text/plain; charset=utf-8', 'X-Content-Type-Options': 'nosniff', 'Date': 'Mon, 07 Sep 2020 00:41:25 GMT', 'Content-Length': '19'})
HTTP response body: 404 page not found

您期望发生的事情: 找到自定义对象

如何再现(尽可能最小且精确):

    from kubernetes import client
from kubernetes.client import Configuration
from kubernetes.config import kube_config

class K8s(object):
    def __init__(self, configuration_json):
        self.configuration_json = configuration_json
        # self._configuration_json = None

    @property
    def client(self):
        k8_loader = kube_config.KubeConfigLoader(self.configuration_json)
        call_config = type.__call__(Configuration)
        k8_loader.load_and_set(call_config)
        Configuration.set_default(call_config)
        return client

def main():
    cls = {
        "kind": "Config",
        "users": [
            {
                "name": "xyx",
                "user": {
                    "client-key-data": "daksjdkasjdklj==",
                    "client-certificate-data": "skadlkasldk"
                }
            }
        ],
        "clusters": [
            {
                "name": "cluster1",
                "cluster": {
                    "server": "https://cyx.cloud.ibm.com",
                    "certificate-authority-data": "sldklaksdl="
                }
            }
        ],
        "contexts": [
            {
                "name": "cluster1/admin",
                "context": {
                    "user": "admin",
                    "cluster": "cluster1",
                    "namespace": "default"
                }
            }
        ],
        "apiVersion": "v1",
        "preferences": {},
        "current-context": "cluster1/admin"
    }
    
    config_trgt = K8s(configuration_json=cls).client
    api = config_trgt.CustomObjectsApi()
    
    resource = api.get_namespaced_custom_object(
        group="velero.io",
        version="v1",
        namespace="velero",
        plural="backups",
        name="apple"
    )
    print(resource)

if __name__ == "__main__":
    main()

我们需要了解的其他信息吗?: 我能够使用所有其他API,包括create_namespaced_custom_object() 我可以使用"kubectl get backup -n velero"查看该自定义对象

Anything else we need to know?: I am able to use all other api including create_namespaced_custom_object() I can view this custom object using "kubectl get backup -n velero"

CRD https://gist.githubeeafa1/e5e8e5e8e1e/email d030950775b87a60ecfdb4370fbd518169118d26/gistfile1.txt

自定义对象

https://gist.githubflickaf83bff89b1f08b23a76f3bfffffbfbfffbfbfbfbfbfbfbfbfbfbffbfbfbfbfbfbfbfdfbbd&d /raw/030cf503a33a9162251a61380105c719037b90ad/gistfile1.txt

环境:

  • Kubernetes版本(v1.18.6)
  • OS(Linux 20.04):
  • Python版本(3.8.2)
  • Python客户端版本(12.0.0a1)

推荐答案

使用python 3.6,并且不再返回status.code 404.

Used python 3.6 and it no longer returns status.code 404.

这篇关于尝试使用python客户端获取CRD时出现404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆