I am trying to use the python API for kubernetes and I can't seem to be able to execute the request. I think the pipeline is not clear to me.
I am following the steps here: Kubernetes python client: authentication issue
On the remote server:
- I setup my service account and generated the secret as described in the link
- I added the token to my code
I am getting connection refused.
- Am I supposed to import any information from the cluster into the local client?
- Is the port okay?
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()
Output:
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'
Current local client kubectl config view:
apiVersion: v1
clusters: []
contexts: []
current-context: ""
kind: Config
preferences: {}
users: []