【问题标题】:Can not connect to AWS EKS from Ansible无法从 Ansible 连接到 AWS EKS
【发布时间】:2022-01-03 19:57:12
【问题描述】:

我在 ansible 中使用以下 yaml 文件连接到 AWS EKS

- name: Deploy app in new namespace   
  hosts: localhost   
  tasks:
    - name: Create a k8s namespace
      k8s:
        name: my-app
        api_version: v1
        kind: Namespace
        state: present
        kubeconfig: /home/hossam/Documents/eks-terraform-ansible/kubeconfig_myapp-eks-cluster

但我无法连接到集群,总是得到以下结果

[WARNING]: provided hosts list is empty, only localhost is available. Note that
the implicit localhost does not match 'all'

PLAY [Deploy app in new namespace] *********************************************

TASK [Gathering Facts] *********************************************************
ok: [localhost]

TASK [Create a k8s namespace] **************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=80): Max retries exceeded with url: /version (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fce7be90df0>: Failed to establish a new connection: [Errno 111] Connection refused'))
fatal: [localhost]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n  File \"/home/hossam/.local/lib/python3.8/site-packages/urllib3/connection.py\", line 174, in _new_conn\n    conn = connection.create_connection(\n  File \"/home/hossam/.local/lib/python3.8/site-packages/urllib3/util/connection.py\", line 96, in create_connection\n    raise err\n  File \"/home/hossam/.local/lib/python3.8/site-packages/urllib3/util/connection.py\", line 86, in create_connection\n    sock.connect(sa)\nConnectionRefusedError: [Errno 111] Connection refused\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n  File \"/home/hossam/.local/lib/python3.8/site-packages/urllib3/connectionpool.py\", line 699, in urlopen\n    httplib_response = self._make_request(\n  File \"/home/hossam/.local/lib/python3.8/site-packages/urllib3/connectionpool.py\", line 394, in _make_request\n    conn.request(method, url, **httplib_request_kw)\n  File \"/home/hossam/.local/lib/python3.8/site-packages/urllib3/connection.py\", line 239, in request\n    super(HTTPConnection, self).request(method, url, body=body, headers=headers)\n  File \"/usr/lib/python3.8/http/client.py\", line 1252, in request\n    self._send_request(method, url, body, headers, encode_chunked)\n  File \"/usr/lib/python3.8/http/client.py\", line 1298, in _send_request\n    self.endheaders(body, encode_chunked=encode_chunked)\n  File \"/usr/lib/python3.8/http/client.py\", line 1247, in endheaders\n    self._send_output(message_body, encode_chunked=encode_chunked)\n  File \"/usr/lib/python3.8/http/client.py\", line 1007, in _send_output\n    self.send(msg)\n  File \"/usr/lib/python3.8/http/client.py\", line 947, in send\n    self.connect()\n  File \"/home/hossam/.local/lib/python3.8/site-packages/urllib3/connection.py\", line 205, in connect\n    conn = self._new_conn()\n  File \"/home/hossam/.local/lib/python3.8/site-packages/urllib3/connection.py\", line 186, in _new_conn\n    raise NewConnectionError(\nurllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7fce7be90df0>: Failed to establish a new connection: [Errno 111] Connection refused\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n  File \"/home/hossam/.ansible/tmp/ansible-tmp-1641239386.5903301-190642057621938/AnsiballZ_k8s.py\", line 102, in <module>\n    _ansiballz_main()\n  File \"/home/hossam/.ansible/tmp/ansible-tmp-1641239386.5903301-190642057621938/AnsiballZ_k8s.py\", line 94, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/home/hossam/.ansible/tmp/ansible-tmp-1641239386.5903301-190642057621938/AnsiballZ_k8s.py\", line 40, in invoke_module\n    runpy.run_module(mod_name='ansible.modules.clustering.k8s.k8s', init_globals=None, run_name='__main__', alter_sys=True)\n  File \"/usr/lib/python3.8/runpy.py\", line 207, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/usr/lib/python3.8/runpy.py\", line 97, in _run_module_code\n    _run_code(code, mod_globals, init_globals,\n  File \"/usr/lib/python3.8/runpy.py\", line 87, in _run_code\n    exec(code, run_globals)\n  File \"/tmp/ansible_k8s_payload_2u_6kd55/ansible_k8s_payload.zip/ansible/modules/clustering/k8s/k8s.py\", line 279, in <module>\n  File \"/tmp/ansible_k8s_payload_2u_6kd55/ansible_k8s_payload.zip/ansible/modules/clustering/k8s/k8s.py\", line 275, in main\n  File \"/tmp/ansible_k8s_payload_2u_6kd55/ansible_k8s_payload.zip/ansible/module_utils/k8s/raw.py\", line 171, in execute_module\n  File \"/tmp/ansible_k8s_payload_2u_6kd55/ansible_k8s_payload.zip/ansible/module_utils/k8s/common.py\", line 200, in get_api_client\n  File \"/home/hossam/.local/lib/python3.8/site-packages/openshift/dynamic/client.py\", line 71, in __init__\n    self.__discoverer = discoverer(self, cache_file)\n  File \"/home/hossam/.local/lib/python3.8/site-packages/openshift/dynamic/discovery.py\", line 259, in __init__\n    Discoverer.__init__(self, client, cache_file)\n  File \"/home/hossam/.local/lib/python3.8/site-packages/openshift/dynamic/discovery.py\", line 31, in __init__\n    self.__init_cache()\n  File \"/home/hossam/.local/lib/python3.8/site-packages/openshift/dynamic/discovery.py\", line 78, in __init_cache\n    self._load_server_info()\n  File \"/home/hossam/.local/lib/python3.8/site-packages/openshift/dynamic/discovery.py\", line 158, in _load_server_info\n    'kubernetes': self.client.request('get', '/version', serializer=just_json)\n  File \"/home/hossam/.local/lib/python3.8/site-packages/openshift/dynamic/client.py\", line 42, in inner\n    resp = func(self, *args, **kwargs)\n  File \"/home/hossam/.local/lib/python3.8/site-packages/openshift/dynamic/client.py\", line 237, in request\n    return self.client.call_api(\n  File \"/home/hossam/.local/lib/python3.8/site-packages/kubernetes/client/api_client.py\", line 348, in call_api\n    return self.__call_api(resource_path, method,\n  File \"/home/hossam/.local/lib/python3.8/site-packages/kubernetes/client/api_client.py\", line 180, in __call_api\n    response_data = self.request(\n  File \"/home/hossam/.local/lib/python3.8/site-packages/kubernetes/client/api_client.py\", line 373, in request\n    return self.rest_client.GET(url,\n  File \"/home/hossam/.local/lib/python3.8/site-packages/kubernetes/client/rest.py\", line 239, in GET\n    return self.request(\"GET\", url,\n  File \"/home/hossam/.local/lib/python3.8/site-packages/kubernetes/client/rest.py\", line 212, in request\n    r = self.pool_manager.request(method, url,\n  File \"/home/hossam/.local/lib/python3.8/site-packages/urllib3/request.py\", line 74, in request\n    return self.request_encode_url(\n  File \"/home/hossam/.local/lib/python3.8/site-packages/urllib3/request.py\", line 96, in request_encode_url\n    return self.urlopen(method, url, **extra_kw)\n  File \"/home/hossam/.local/lib/python3.8/site-packages/urllib3/poolmanager.py\", line 375, in urlopen\n    response = conn.urlopen(method, u.request_uri, **kw)\n  File \"/home/hossam/.local/lib/python3.8/site-packages/urllib3/connectionpool.py\", line 783, in urlopen\n    return self.urlopen(\n  File \"/home/hossam/.local/lib/python3.8/site-packages/urllib3/connectionpool.py\", line 783, in urlopen\n    return self.urlopen(\n  File \"/home/hossam/.local/lib/python3.8/site-packages/urllib3/connectionpool.py\", line 783, in urlopen\n    return self.urlopen(\n  File \"/home/hossam/.local/lib/python3.8/site-packages/urllib3/connectionpool.py\", line 755, in urlopen\n    retries = retries.increment(\n  File \"/home/hossam/.local/lib/python3.8/site-packages/urllib3/util/retry.py\", line 574, in increment\n    raise MaxRetryError(_pool, url, error or ResponseError(cause))\nurllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=80): Max retries exceeded with url: /version (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fce7be90df0>: Failed to establish a new connection: [Errno 111] Connection refused'))\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}

PLAY RECAP *********************************************************************
localhost                  : ok=1    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0  

【问题讨论】:

    标签: python ansible devops amazon-eks aws-devops


    【解决方案1】:

    解决办法是将Kubernetes版本降级到v11.0.0

    pip3 install -Iv kubernetes==11.0.0
    

    【讨论】:

      猜你喜欢
      • 2021-01-22
      • 2018-01-03
      • 2016-08-24
      • 2019-07-28
      • 2022-10-20
      • 2022-11-03
      • 2020-01-26
      • 1970-01-01
      • 2021-06-10
      相关资源
      最近更新 更多