Kubernetes python eviction api 抱怨'Name parameter required.'



我试图创建一个python脚本来根据某些条件驱逐节点,但我在获取create_namespaced_pod_viction时遇到了问题举止得体。从api文档中可以看出,我的语法看起来非常正确。感谢您的帮助。我还将提到kubernetes集群在AWS EKS 上是1.10

for i in pods.items:
print("Deleting pod: ", i.metadata.name, i.metadata.namespace, node)
body = kubernetes.client.V1beta1Eviction()
api_response = v1.create_namespaced_pod_eviction(i.metadata.name, i.metadata.namespace, body, dry_run='All', include_uninitialized='True', pretty='True')

这是输出:

('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 105, in <module>
main()
File "src/update_workernodes.py", line 99, in main
evict_pods(old_worker_dns)
File "src/update_workernodes.py", line 82, in evict_pods
api_response = v1.create_namespaced_pod_eviction(name=i.metadata.name, namespace=i.metadata.namespace,     body=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 02:34:52 GMT', 'Audit-Id':     '7a3725ac-5b1c-470b-a743-0af202a56f7c', '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
}

对于那些偶然发现这一点的人,我可以通过以下操作来实现这一点:

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)

相关内容

  • 没有找到相关文章

最新更新