【问题标题】:k8s_api connection time out in Jenkins pipelineJenkins管道中的k8s_api连接超时
【发布时间】:2019-09-01 22:09:31
【问题描述】:

我想使用 Kubernetes API 列出集群中存在的命名空间,即使用 list_namespace 方法。

当我在我的 Linux 机器上运行下面提到的代码时,它运行良好。

我创建了一个 Jenkins 管道作业并调用 python 文件,如下所示抛出连接超时错误。

如果我在同一个 Jenkins 文件中执行 kubectl get ns,我将得到输出。

我认为代理不允许这样做。但找不到如何解决它。

我的 Python 代码:

config.load_kube_config(os.environ['KUBE_CONFIG'])
v1_api = client.CoreV1Api()
api_instance = kubernetes.client.CoreV1Api()

try: 
    api_response = api_instance.list_namespace(limit="1")
    pprint(api_response)
except Exception as e:
    print("Exception when calling CoreV1Api->list_namespace: %s\n" % e)

sys.exit("EXITING")

我运行的命令:

export KUBE_CONFIG=${env.WORKSPACE}/.kube/kube_config
python36 listns.py 

错误:

警告重试(重试(总计=0,连接=无,读取=无, redirect=None, status=None)) 连接中断后 'NewConnectionError(': 建立新连接失败: [Errno 110] 连接超时',)': /api/v1/namespaces?limit=1

调用 CoreV1Api->list_namespace 时出现异常: HTTPSConnectionPool(host='XXXXXXX', port=xxxx): 超过最大重试次数 带有 url:/api/v1/namespaces?limit=1(由 NewConnectionError(': 建立新连接失败:[Errno 110] 连接超时',))

【问题讨论】:

    标签: python python-3.x kubernetes jenkins-pipeline urllib3


    【解决方案1】:

    通过使用配置类传递代理得到修复:

    configuration = kubernetes.client.Configuration()
    configuration.proxy='http://www-proxy-<myproxyserver>'
    
    api_instance = kubernetes.client.ApiClient(configuration)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-10-24
      • 2020-12-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-26
      • 2018-08-07
      相关资源
      最近更新 更多