使用kubernetes客户机corev1api运行“connect_get_namespaced_pod_exec”会产生错误的请求

2024-06-25 07:26:39 发布

您现在位置:Python中文网/ 问答频道 /正文

kubernetes客户端corev1api connect_get_namespaced_pod_exec无法为python运行。在

我已经检查了python version==2.7和pip freeze-ipaddress==1.0.22、urllib3==1.24.1和websocket client==0.54.0是满足要求的版本,如下所述:https://github.com/kubernetes-client/python/blob/master/README.md#hostname-doesnt-match 跟踪了这个线程上的问题-https://github.com/kubernetes-client/python/issues/36-帮助不大。在

尝试使用此处建议的流-https://github.com/kubernetes-client/python/blob/master/examples/exec.py

跑步:

api_response = stream(core_v1_api.connect_get_namespaced_pod_exec,
                      name, namespace,
                      command=exec_command,
                      stderr=True, stdin=False,
                      stdout=True, tty=False)

出现以下错误:

ApiException: (0) Reason: hostname '10.47.7.95' doesn't match either of '', 'cluster.local'

没有直接使用CoreV1Api的流-

跑步:

^{pr2}$

出现以下错误:

ApiException: (400) Reason: Bad Request HTTP response headers: HTTPHeaderDict({'Date': 'Sat, 05 Jan 2019 08:01:22 GMT', 'Content-Length': '139', 'Content-Type': 'application/json'}) HTTP response body: {"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"Upgrade request required","reason":"BadRequest","code":400}


Tags: httpsgithubmastercomclientgetresponsematch
1条回答
网友
1楼 · 发布于 2024-06-25 07:26:39

我编写了一个简单的程序来检查:

from kubernetes import client, config
from kubernetes.stream import stream

# create an instance of the API class

config.load_kube_config()
api_instance = client.CoreV1Api()

exec_command = [
    '/bin/sh',
    '-c',
    'echo This is Prafull Ladha and it is test function']
resp = stream(api_instance.connect_get_namespaced_pod_exec, "nginx-deployment-76bf4969df-467z2", 'default',
              command=exec_command,
              stderr=True, stdin=False,
              stdout=True, tty=False)
print("Response: " + resp)

它对我来说工作得很好。在

我相信您使用minikube进行开发。它无法识别您的主机名。您可以通过在程序中禁用assert_hostname来使其工作,例如:

^{pr2}$

这应该可以解决您的问题。在

相关问题 更多 >