我使用python k8s客户端成功地快照了我的卷
然而,我得到了下面的信息
我在集群中没有相同的卷快照
为什么会这样
代码:
def create_快照(名称空间,pvc_名称):
snapshot_class = "snapshotclass"
snapshot_name = f"snapshot-{pvc_name}"
snapshot_resource = {
"apiVersion": "snapshot.storage.k8s.io/v1beta1",
"kind": "VolumeSnapshot",
"metadata": {"name": snapshot_name},
"spec": {
"volumeSnapshotClassName": snapshot_class,
"source": {"persistentVolumeClaimName": pvc_name}
}
}
res = custom_api.create_namespaced_custom_object(
group="snapshot.storage.k8s.io",
version="v1beta1",
namespace= namespace,
plural="volumesnapshots",
body=snapshot_resource,
)
print(res)
create_snapshot("test", "test-pvc")
volumesnapshot已成功创建,但我收到一条消息:
File "/home/new/my/test/rescheduler/utils/k8s_controller.py", line 72, in create_snapshot
body=snapshot_resource,
File "/home/new/my/test/venv/lib/python3.6/site-packages/kubernetes/client/api/custom_objects_api.py", line 225, in create_namespaced_custom_object
return self.create_namespaced_custom_object_with_http_info(group, version, namespace, plural, body, **kwargs) # noqa: E501
File "/home/new/my/test/venv/lib/python3.6/site-packages/kubernetes/client/api/custom_objects_api.py", line 358, in create_namespaced_custom_object_with_http_info
collection_formats=collection_formats)
File "/home/new/my/test/venv/lib/python3.6/site-packages/kubernetes/client/api_client.py", line 353, in call_api
_preload_content, _request_timeout, _host)
File "/home/new/my/test/venv/lib/python3.6/site-packages/kubernetes/client/api_client.py", line 184, in __call_api
_request_timeout=_request_timeout)
File "/home/new/my/test/venv/lib/python3.6/site-packages/kubernetes/client/api_client.py", line 397, in request
body=body)
File "/home/new/my/test/venv/lib/python3.6/site-packages/kubernetes/client/rest.py", line 280, in POST
body=body)
File "/home/new/my/test/venv/lib/python3.6/site-packages/kubernetes/client/rest.py", line 233, in request
raise ApiException(http_resp=r)
kubernetes.client.exceptions.ApiException: (409)
Reason: Conflict
HTTP response headers: HTTPHeaderDict({'Audit-Id': 'dec3c73a-e5fc-4c63-8d1a-6e2e6c6600e1', 'Cache-Control': 'no-cache, private', 'Content-Type': 'application/json', 'Date': 'my, 25 Apr 2021 10:50:52 GMT', 'Content-Length': '346'})
HTTP response body: {"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"volumesnapshots.snapshot.storage.k8s.io \"snapshot-test-pvc\" already exists","reason":"AlreadyExists","details":{"name":"snapshot-test-pvc,"group":"snapshot.storage.k8s.io","kind":"volumesnapshots"},"code":409}
将此答案发布为社区wiki,以给出在尝试使用上述代码片段创建资源时遇到错误
409
的可能原因之一请随意扩展它
问题中遇到的错误:
表示该资源已存在于群集中。要检查群集中是否存在资源,可以运行以下命令:
$ kubectl get volumesnapshots -A
$ kubectl describe volumesnapshots RESOURCE_NAME -A
我使用了问题中的代码,没有任何问题。行动方针如下:
VolumeSnapshot
已成功创建在尝试对已创建的资源运行
$ kubectl create -f resource.yaml -v=4
时,也可以看到此错误对于任何感兴趣的人来说,这里是问题中使用的代码的minimal, reproducible example(它丢失了
import
,并且def
放错了位置):额外资源:
相关问题 更多 >
编程相关推荐