我正在尝试将 python API 用于 kubernetes,但我似乎无法执行该请求。我认为管道对我来说并不清楚。
我正在按照这里的步骤操作:Kubernetes python 客户端:身份验证问题
在远程服务器上:
- 我设置了我的服务帐户并生成了链接中描述的秘密
- 我将令牌添加到我的代码中
我被拒绝连接。
- 我应该将集群中的任何信息导入本地客户端吗?
- 港口好吗?
from kubernetes import client, config
def main():
configuration = client.Configuration()
configuration.host = "http://my_ip:8080"
configuration.api_key_prefix['authorization'] = "Bearer"
configuration.api_key['authorization'] = "my_token"
v1 = client.CoreV1Api()
print("Listing pods with their IPs:")
ret = v1.list_pod_for_all_namespaces(watch=False)
for i in ret.items:
print("%s\t%s\t%s" %
(i.status.pod_ip, i.metadata.namespace, i.metadata.name))
if __name__ == '__main__':
main()
输出:
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='xx.xx.xx.xx', port=8080): Max retries exceeded with url: /api/v1/pods?watch=False (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x1118e5668>: Failed to establish a new connection: [Errno 61] Connection refused'
当前本地客户端 kubectl 配置视图:
apiVersion: v1
clusters: []
contexts: []
current-context: ""
kind: Config
preferences: {}
users: []