Im having trouble getting the create_namespaced_pod_eviction to function. From what I can tell from the api documentation my syntax looks ok. The kubernetes cluster is 1.10 on AWS EKS
for node in nodes:
field_selector = 'spec.nodeName='+ node
v1 = kubernetes.client.CoreV1Api()
pods = v1.list_pod_for_all_namespaces(watch=False, field_selector=field_selector)
body = kubernetes.client.V1beta1Eviction()
print("")
for i in pods.items:
print("Deleting pod: ", i.metadata.name, i.metadata.namespace, node)
api_response = v1.create_namespaced_pod_eviction(i.metadata.name, i.metadata.namespace, body, dry_run='All', include_uninitialized='True', pretty='True')
pprint(api_response)
('Deleting pod: ', 'ambassador-5d86576878-4kv6w', 'istio-system', 'ip-10-72-20-161.ec2.internal')
Traceback (most recent call last):
File "src/update_workernodes.py", line 107, in <module>
main()
File "src/update_workernodes.py", line 101, in main
evict_pods(old_worker_dns)
kubernetes==8.0.0
File "src/update_workernodes.py", line 84, in evict_pods
api_response = v1.create_namespaced_pod_eviction(i.metadata.name, i.metadata.namespace, body, dry_run='All', include_uninitialized='True', pretty='True')
File "/usr/local/lib/python2.7/site-packages/kubernetes/client/apis/core_v1_api.py", line 6353, in create_namespaced_pod_eviction
(data) = self.create_namespaced_pod_eviction_with_http_info(name, namespace, body, **kwargs)
File "/usr/local/lib/python2.7/site-packages/kubernetes/client/apis/core_v1_api.py", line 6450, in create_namespaced_pod_eviction_with_http_info
collection_formats=collection_formats)
File "/usr/local/lib/python2.7/site-packages/kubernetes/client/api_client.py", line 321, in call_api
_return_http_data_only, collection_formats, _preload_content, _request_timeout)
File "/usr/local/lib/python2.7/site-packages/kubernetes/client/api_client.py", line 155, in __call_api
_request_timeout=_request_timeout)
File "/usr/local/lib/python2.7/site-packages/kubernetes/client/api_client.py", line 364, in request
body=body)
File "/usr/local/lib/python2.7/site-packages/kubernetes/client/rest.py", line 266, in POST
body=body)
File "/usr/local/lib/python2.7/site-packages/kubernetes/client/rest.py", line 222, in request
raise ApiException(http_resp=r)
kubernetes.client.rest.ApiException: (400)
Reason: Bad Request
HTTP response headers: HTTPHeaderDict({'Date': 'Tue, 13 Nov 2018 17:25:08 GMT', 'Audit-Id': '3ba92f41-4346-4f7c-ae24-fd28dbc41d52', 'Content-Length': '175', 'Content-Type': 'application/json'})
HTTP response body: {
"kind": "Status",
"apiVersion": "v1",
"metadata": {
},
"status": "Failure",
"message": "Name parameter required.",
"reason": "BadRequest",
"code": 400
}
You might want to pass a body dictionary when you initialize the create_namespaced_pod_eviction, see this link about the drain command
I know this is pretty late, but I found this issue via googling for the same issue so I wanted to make sure anyone who stumbled across this had a solution.
I was able to get this working by doing the following:
podName = 'insert-name-of-pod'
podNamespace = 'insert-namespace-of-pod'
body = client.V1beta1Eviction(metadata=client.V1ObjectMeta(name=podName, namespace=podNamespace))
api_response = v1.create_namespaced_pod_eviction(name=podName, namespace=podNamespace, body=body)
Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.
If this issue is safe to close now please do so with /close.
Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale
Stale issues rot after 30d of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.
If this issue is safe to close now please do so with /close.
Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle rotten
Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.
Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/close
@fejta-bot: Closing this issue.
In response to this:
Rotten issues close after 30d of inactivity.
Reopen the issue with/reopen.
Mark the issue as fresh with/remove-lifecycle rotten.Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/close
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.
Most helpful comment
I know this is pretty late, but I found this issue via googling for the same issue so I wanted to make sure anyone who stumbled across this had a solution.
I was able to get this working by doing the following: