繁体   English   中英

如何使用 python 复制 pod

[英]How to replicate pod using python

我正在使用 python 与 Kube.netes 进行交互。 我需要删除现有的 pod 并使用不同的名称和 PVC 重新创建它。 从 Python API 文档我了解到 Python 提供 API create_namespaced_pod 接受 body 作为参数,假设是 Pod 特定数据。 但是我不想构造这个主体参数从旧 pod 获取数据并在主体中再次设置。 有没有其他方法可以让我读取旧的 pod 内容、更新 PVC 和 pod 名称并调用 create_namespaced_pod 方法来创建新的 pod?

我试图将 pod 的内容传递给 create_namespaced_pod 方法。 但它没有给出任何例外,但 Pod 没有被创建。 下面的代码打印“-- created pod---”

targetPodResult = v1.read_namespaced_pod(podname, obj.metadata.namespace, async_req=True)  
targetPod = targetPodResult.get()
targetPod.metadata.name = targetPod.metadata.name + "_new"
print(targetPod)
v1.create_namespaced_pod('default', targetPod, async_req=True)
print("--  created pod---")

我现在可以使用 body = targetPod 的不同方法变体来创建 pod,如下所示。 另外,我需要将旧 pod 的 resource_version 设置为“无”

v1.create_namespaced_pod(body = targetPod, namespace = 'default')

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM