Can't delete pods using Kubernetes API
See original GitHub issueI am using the python client library for the API. I am using the following code :
def delete_pod(name, namespace):
api_instance = client.CoreV1Api()
body = client.V1DeleteOptions()
api_response = api_instance.delete_namespaced_pod(name, namespace, body)
return api_response
print delete_pod('kargo-3','default')
But I get the following error :
2017-06-26 17:32:19,852 WARNING Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f2e0ce059d0>: Failed to establish a new connection: [Errno 111] Connection refused',)': /api/v1/namespaces/default/pods/kargo-3
2017-06-26 17:32:19,853 WARNING Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f2e0ce05b50>: Failed to establish a new connection: [Errno 111] Connection refused',)': /api/v1/namespaces/default/pods/kargo-3
2017-06-26 17:32:19,853 WARNING Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f2e0ce05c90>: Failed to establish a new connection: [Errno 111] Connection refused',)': /api/v1/namespaces/default/pods/kargo-3
Traceback (most recent call last):
File "utility_pods.py", line 41, in <module>
print delete_pod('kargo-3','default')
File "utility_pods.py", line 37, in delete_pod
api_response = api_instance.delete_namespaced_pod(name, namespace, body)
File "/home/piyush/.local/lib/python2.7/site-packages/kubernetes/client/apis/core_v1_api.py", line 9726, in delete_namespaced_pod
(data) = self.delete_namespaced_pod_with_http_info(name, namespace, body, **kwargs)
File "/home/piyush/.local/lib/python2.7/site-packages/kubernetes/client/apis/core_v1_api.py", line 9831, in delete_namespaced_pod_with_http_info
collection_formats=collection_formats)
File "/home/piyush/.local/lib/python2.7/site-packages/kubernetes/client/api_client.py", line 329, in call_api
_return_http_data_only, collection_formats, _preload_content, _request_timeout)
File "/home/piyush/.local/lib/python2.7/site-packages/kubernetes/client/api_client.py", line 153, in __call_api
_request_timeout=_request_timeout)
File "/home/piyush/.local/lib/python2.7/site-packages/kubernetes/client/api_client.py", line 406, in request
body=body)
File "/home/piyush/.local/lib/python2.7/site-packages/kubernetes/client/rest.py", line 265, in DELETE
body=body)
File "/home/piyush/.local/lib/python2.7/site-packages/kubernetes/client/rest.py", line 175, in request
headers=headers)
File "/home/piyush/.local/lib/python2.7/site-packages/urllib3/request.py", line 66, in request
**urlopen_kw)
File "/home/piyush/.local/lib/python2.7/site-packages/urllib3/request.py", line 87, in request_encode_url
return self.urlopen(method, url, **extra_kw)
File "/home/piyush/.local/lib/python2.7/site-packages/urllib3/poolmanager.py", line 321, in urlopen
response = conn.urlopen(method, u.request_uri, **kw)
File "/home/piyush/.local/lib/python2.7/site-packages/urllib3/connectionpool.py", line 678, in urlopen
**response_kw)
File "/home/piyush/.local/lib/python2.7/site-packages/urllib3/connectionpool.py", line 678, in urlopen
**response_kw)
File "/home/piyush/.local/lib/python2.7/site-packages/urllib3/connectionpool.py", line 678, in urlopen
**response_kw)
File "/home/piyush/.local/lib/python2.7/site-packages/urllib3/connectionpool.py", line 649, in urlopen
_stacktrace=sys.exc_info()[2])
File "/home/piyush/.local/lib/python2.7/site-packages/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/namespaces/default/pods/kargo-3 (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f2e0ce0bd90>: Failed to establish a new connection: [Errno 111] Connection refused',))
At first I thought this was because I wasn’t providing
kubernetes.client.configuration.api_key['authorization'] = 'YOUR_API_KEY'
But then I am able to use the APIs to get pod list node list, etc. They should also require authorization. Any clue?
Issue Analytics
- State:
- Created 6 years ago
- Comments:15 (4 by maintainers)
Top Results From Across the Web
Force Delete StatefulSet Pods - Kubernetes
This page shows how to delete Pods which are part of a stateful set, and explains the considerations to keep in mind when...
Read more >delete pods forcefully kubernetes API - Stack Overflow
I run your command kubectl delete pod --grace-period=0 --force <pod_name> --v 10 and notice the output logs and found following
Read more >Forcefully Delete Kubernetes Pod - Platform9 Knowledge Base
A pod is stuck in terminating state as per the Kubectl output. Deletion of pod fails even after running the command.
Read more >What Should I Do If Pods in the Terminating State Cannot Be ...
After the node is restored, the pods in the Terminating state are automatically deleted. However, some pods remain in the Terminating state.
Read more >How to Delete Pods from a Kubernetes Node with Examples
Pods can be deleted simply using the kubectl delete pod command. However, the challenge is usually to maintain application uptime and avoid ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I suspect you have a Python syntax problem in your script unrelated to the kubernetes package, but I’m not sure because the script you’ve posted isn’t formatted correctly. I have edited your script slightly and it seems to work for me.
I got a similar error and was able to address this by using the following code to explicitly set api_client.
Here’s the code that works. This works when running inside a Docker container on my local machine talking to a remote k8s cluster.
Here’s the code that doesn’t work
which produces output
So the problem appears to be that api_client ends up using host ‘localhost’ for the K8s master which is incorrect; my k8s master is remote and has an actual ip address.
Interestingly I only hit this problem when running the above snippet inside a container on my local machine. However, I don’t hit this problem when running on my host machine. However, there’s no guarantee that my python environments are equivalent.