添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
沉着的烈马  ·  K8s集群存储NAS替换NFS·  1 月前    · 
温暖的小马驹  ·  工作负载 | Kubernetes·  1 月前    · 
要出家的大熊猫  ·  Geeky Blinder·  4 周前    · 
直爽的跑步机  ·  Kubernetes RBAC ...·  3 周前    · 
玩篮球的创口贴  ·  Prometheus ...·  2 周前    · 
胆小的咖啡  ·  GLSL/extensions/ext/GL ...·  4 月前    · 
坏坏的莴苣  ·  保密协议-泉州人大·  7 月前    · 
玩命的水桶  ·  (-215:Assertion ...·  7 月前    · 

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement . We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kubernetes version (use kubectl version ):
Client Version: version.Info{Major:"1", Minor:"6", GitVersion:"v1.6.4", GitCommit:"d6f433224538d4f9ca2f7ae19b252e6fcb66a3ae", GitTreeState:"clean", BuildDate:"2017-05-19T18:44:27Z", GoVersion:"go1.7.5", Compiler:"gc", Platform:"linux/amd64"}

Environment :

  • Cloud provider or hardware configuration :
    minikube, gcloud
  • OS (e.g. from /etc/os-release):
    host OS: Ubuntu 16.04.2 LTS
    pod OS: CentOS Linux 7 (Core)
  • Kernel (e.g. uname -a ):
    host OS: Linux 4.4.0-78-generic Improve e2e (improve #3) #99 -Ubuntu SMP Thu Apr 27 15:29:09 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
    pod OS: Linux 4.7.2 Unit test coverage in Kubelet is lousy. (~30%) #1 SMP Fri Apr 7 10:38:40 PDT 2017 x86_64 x86_64 x86_64 GNU/Linux
  • Install tools :
  • Others :
  • What happened :
    Trying to access api service from the pod in python:

    from kubernetes import client, config
    core_v1 = client.CoreV1Api()
    config.load_incluster_config()
    core_v1.list_node()

    results in following error:

    # python
    Python 2.7.5 (default, Nov  6 2016, 00:28:07) 
    [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> from kubernetes import client, config
    >>> core_v1 = client.CoreV1Api()
    >>> config.load_incluster_config()
    >>> core_v1.list_node()         
    2017-06-14 13:52:41,486 WARNING Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x36c0e50>: Failed to establish a new connection: [Errno 111] Connection refused',)': /api/v1/nodes
    2017-06-14 13:52:41,487 WARNING Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x36b5b50>: Failed to establish a new connection: [Errno 111] Connection refused',)': /api/v1/nodes
    2017-06-14 13:52:41,487 WARNING Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x36b5c90>: Failed to establish a new connection: [Errno 111] Connection refused',)': /api/v1/nodes
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "build/bdist.linux-x86_64/egg/kubernetes/client/apis/core_v1_api.py", line 13284, in list_node
      File "build/bdist.linux-x86_64/egg/kubernetes/client/apis/core_v1_api.py", line 13377, in list_node_with_http_info
      File "build/bdist.linux-x86_64/egg/kubernetes/client/api_client.py", line 329, in call_api
      File "build/bdist.linux-x86_64/egg/kubernetes/client/api_client.py", line 153, in __call_api
      File "build/bdist.linux-x86_64/egg/kubernetes/client/api_client.py", line 361, in request
      File "build/bdist.linux-x86_64/egg/kubernetes/client/rest.py", line 240, in GET
      File "build/bdist.linux-x86_64/egg/kubernetes/client/rest.py", line 214, in request
      File "/usr/lib/python2.7/site-packages/urllib3-1.21.1-py2.7.egg/urllib3/request.py", line 66, in request
        **urlopen_kw)
      File "/usr/lib/python2.7/site-packages/urllib3-1.21.1-py2.7.egg/urllib3/request.py", line 87, in request_encode_url
        return self.urlopen(method, url, **extra_kw)
      File "/usr/lib/python2.7/site-packages/urllib3-1.21.1-py2.7.egg/urllib3/poolmanager.py", line 321, in urlopen
        response = conn.urlopen(method, u.request_uri, **kw)
      File "/usr/lib/python2.7/site-packages/urllib3-1.21.1-py2.7.egg/urllib3/connectionpool.py", line 678, in urlopen
        **response_kw)
      File "/usr/lib/python2.7/site-packages/urllib3-1.21.1-py2.7.egg/urllib3/connectionpool.py", line 678, in urlopen
        **response_kw)
      File "/usr/lib/python2.7/site-packages/urllib3-1.21.1-py2.7.egg/urllib3/connectionpool.py", line 678, in urlopen
        **response_kw)
      File "/usr/lib/python2.7/site-packages/urllib3-1.21.1-py2.7.egg/urllib3/connectionpool.py", line 649, in urlopen
        _stacktrace=sys.exc_info()[2])
      File "/usr/lib/python2.7/site-packages/urllib3-1.21.1-py2.7.egg/urllib3/util/retry.py", line 388, in increment
        raise MaxRetryError(_pool, url, error or ResponseError(cause))
    urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='localhost', port=443): Max retries exceeded with url: /api/v1/nodes (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x36b5d90>: Failed to establish a new connection: [Errno 111] Connection refused',))
    

    For some reason HTTPSConnectionPool is trying to access localhost instead of API server, though API url in kubernetes configuration seems to be correct:

    >>> from kubernetes.client import configuration
    >>> configuration.host
    'https://10.0.0.1:443'
    

    What you expected to happen:
    get a list of nodes

    How to reproduce it (as minimally and precisely as possible):
    described above

    Anything else we need to know:

    @magescher supposedly it is fixed in 3.0 . As a workaround I used following:

            os.environ['KUBERNETES_SERVICE_HOST'] = 'kubernetes'
            config.load_incluster_config()
    

    @magescher supposedly it is fixed in 3.0 . As a workaround I used following:

            os.environ['KUBERNETES_SERVICE_HOST'] = 'kubernetes'
            config.load_incluster_config()
    

    import os.path
    import yaml
    import boto3
    from kubernetes import client, config
    from auth import EKSAuth
    from os import path

    os.environ['KUBERNETES_SERVICE_HOST'] = 'kubernetes'
    config.load_incluster_config()

    Configure your cluster name and region here

    KUBE_FILEPATH = '/tmp/rconfig'
    CLUSTER_NAME = 'pre-imputation'
    REGION = 'us-east-1'

    We assume that when the Lambda container is reused, a kubeconfig file exists.

    If it does not exist, it creates the file.

    with open("./rconfig", 'r') as c:
    job = yaml.safe_load(c)
    with open(KUBE_FILEPATH, 'w') as outfile:
    yaml.dump(job, outfile, default_flow_style=False)

    def handler(event, context):
    #def handler():
    # Get Token
    eks = EKSAuth(CLUSTER_NAME)
    token = eks.get_token()
    # Configure
    print("configure")
    config.load_kube_config(KUBE_FILEPATH)
    configuration = client.Configuration()
    configuration.api_key['authorization'] = token
    configuration.api_key_prefix['authorization'] = 'Bearer'
    # API
    print("api call")
    api = client.ApiClient(configuration)

    v1 = client.CoreV1Api(api)

    with open("./job.yaml",'r') as f:
        job = yaml.safe_load(f)
        k8s_apps_v1 = client.BatchV1Api(api)
        resp = k8s_apps_v1.create_namespaced_job(
            body=job,namespace="default")
        print("job created. name='%s'" % resp.metadata.name)
    

    #handler()

    i m getting below error

    Response:
    "errorMessage": "Service host/port is not set.",
    "errorType": "ConfigException",
    "stackTrace": [
    " File "/var/lang/lib/python3.8/imp.py", line 234, in load_module\n return load_source(name, filename, file)\n",
    " File "/var/lang/lib/python3.8/imp.py", line 171, in load_source\n module = _load(spec)\n",
    " File "", line 702, in _load\n",
    " File "", line 671, in _load_unlocked\n",
    " File "", line 783, in exec_module\n",
    " File "", line 219, in _call_with_frames_removed\n",
    " File "/var/task/main.py", line 9, in \n config.load_incluster_config()\n",
    " File "/opt/python/kubernetes/config/incluster_config.py", line 118, in load_incluster_config\n InClusterConfigLoader(\n",
    " File "/opt/python/kubernetes/config/incluster_config.py", line 54, in load_and_set\n self._load_config()\n",
    " File "/opt/python/kubernetes/config/incluster_config.py", line 62, in _load_config\n raise ConfigException("Service host/port is not set.")\n"