与主机名“ x.x.x.x”都不匹配与“主机名”,“ kubernetes”,“ kubernetes.default”,“ kubernetes.default

时间:2019-03-05 14:02:49

标签: python-2.7 kubernetes

尝试使用python在kubernetes中的容器上执行命令。 Python 2.7.12 Ubuntu服务器16。

pip show kubernetes 名称:kubernetes 版本:8.0.1 摘要:Kubernetes python客户端

  

已满足要求:/usr/local/lib/python2.7/dist-packages(8.0.1)中的kubernetes   已经满足的要求:ipaddress> = 1.0.17; /usr/local/lib/python2.7/dist-packages中的python_version ==“ 2.7”(来自kubernetes)(1.0.17)   已经满足的要求:/usr/local/lib/python2.7/dist-packages中的六个> = 1.9.0(来自kubernetes)(1.12.0)   已满足要求:/usr/local/lib/python2.7/dist-packages中的request-oauthlib(来自kubernetes)(1.2.0)   已经满足的要求:/usr/local/lib/python2.7/dist-packages中的pyyaml> = 3.12(来自kubernetes)(3.13)   已满足要求:/usr/local/lib/python2.7/dist-packages中的python-dateutil> = 2.5.3(来自kubernetes)(2.8.0)   已满足要求:/usr/local/lib/python2.7/dist-packages中的certifi> = 14.05.14(来自kubernetes)(2018.11.29)   已经满足的要求:/usr/local/lib/python2.7/dist-packages中的adal> = 1.0.2(来自kubernetes)(1.2.1)   已经满足的要求:/usr/local/lib/python2.7/dist-packages中的websocket-client!= 0.40.0,!= 0.41。,!= 0.42。,> = 0.32.0 (来自kubernetes)(0.55.0)   已经满足的要求:/usr/local/lib/python2.7/dist-packages中的urllib3> = 1.23(来自kubernetes)(1.23)   已经满足的要求:/usr/local/lib/python2.7/dist-packages中的google-auth> = 1.0.1(来自kubernetes)(1.6.3)   已经满足的要求:/usr/local/lib/python2.7/dist-packages中的setuptools> = 21.0.0(来自kubernetes)(40.8.0)   已满足要求:/usr/local/lib/python2.7/dist-packages中的请求(来自kubernetes)(2.21.0)   已经满足要求:/usr/local/lib/python2.7/dist-packages中的oauthlib> = 3.0.0(来自requests-oauthlib-> kubernetes)(3.0.1)   已经满足的要求:/usr/local/lib/python2.7/dist-packages中的PyJWT> = 1.0.0(来自adal> = 1.0.2-> kubernetes)(1.7.1)   已经满足的要求:/usr/local/lib/python2.7/dist-packages中的密码学> = 1.1.0(来自adal> = 1.0.2-> kubernetes)(2.6.1)   已经满足的要求:/usr/local/lib/python2.7/dist-packages中的rsa> = 3.1.4(来自google-auth> = 1.0.1-> kubernetes)(4.0)   已经满足的要求:/usr/local/lib/python2.7/dist-packages中的cachetools> = 2.0.0(来自google-auth> = 1.0.1-> kubernetes)(3.1.0)   已经满足的要求:/usr/local/lib/python2.7/dist-packages中的pyasn1-modules> = 0.2.1(来自google-auth> = 1.0.1-> kubernetes)(0.2.4)   已经满足的要求:/usr/local/lib/python2.7/dist-packages中的chardet <3.1.0,> = 3.0.2(来自requests-> kubernetes)(3.0.4)   已经满足的要求:/usr/local/lib/python2.7/dist-packages中的idna <2.9,> = 2.5(来自request-> kubernetes)(2.8)   已经满足的要求:enum34; /usr/local/lib/python2.7/dist-packages中的python_version <“ 3”(来自密码学> = 1.1.0-> adal> = 1.0.2-> kubernetes)(1.1.6)   已经满足的要求:/usr/local/lib/python2.7/dist-packages中的cffi!= 1.11.3,> = 1.8(来自密码学> = 1.1.0-> adal> = 1.0.2-> kubernetes)( 1.12.2)   已经满足的要求:/usr/local/lib/python2.7/dist-packages中的asn1crypto> = 0.21.0(来自密码学> = 1.1.0-> adal> = 1.0.2-> kubernetes)(0.24.0)   已经满足的要求:/usr/local/lib/python2.7/dist-packages中的pyasn1> = 0.1.3(来自rsa> = 3.1.4-> google-auth> = 1.0.1-> kubernetes)(0.4。 5)   已经满足要求:/usr/local/lib/python2.7/dist-packages中的pycparser(来自cffi!= 1.11.3,> = 1.8-> cryptography> = 1.1.0-> adal> = 1.0.2-> kubernetes)(2.19)

但是,我们失败了:

  

原因:主机名“ xxxx”与“ k8s-master-240”,“ kubernetes”,“ kubernetes.default”,“ kubernetes.default.svc”,“ kubernetes.default.svc.cluster”都不匹配。本地的

代码:

from kubernetes import client, config, stream
from kubernetes.client.apis import core_v1_api
from kubernetes.client import configuration
from kubernetes.client.rest import ApiException

def execute_cmd(container_name, cmd):
    try:
        config.load_kube_config()
        configuration.assert_hostname = False
        k8s_api = core_v1_api.CoreV1Api()
        resp = stream.stream(k8s_api.connect_get_namespaced_pod_exec,
                             name=container_name,namespace=namespace,
                             command=cmd,stderr=True, stdin=False,
                             stdout=True, tty=False)
        logger.info('Response: {}.'.format(resp))

        return resp
    except ApiException as e:
        logger.error(e.reason)

检查了依赖性,将configuration.assert_hostname设置为False。 似乎没有任何作用。寻找解决方案。 这适用于Centos7,Python 2.7.5。

0 个答案:

没有答案