Reputation: 53
I am using python to interact with Kubernetes. I need to delete an existing pod and recreate it with different name and PVC. From Python API documentation I got to know that Python provides API create_namespaced_pod which accepts body as argument which is suppose to be Pod specific data. But I dont want to construct this Body Parameter fetching data from old pod and setting again in body. Is there any other way where in i can read the old pod content, update PVC and pod name and call create_namespaced_pod method to create new pod ?
I tried to pass content of pod to create_namespaced_pod method. But it does not give any exception but Pod does not gets created. Below code prints "-- 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---")
Upvotes: 0
Views: 130
Reputation: 53
i am able to create pod now using different variant of method with body = targetPod like below. also, i need to set resource_version of old pod to 'None'
v1.create_namespaced_pod(body = targetPod, namespace = 'default')
Upvotes: 1