如何通过Python Kubernetes API实现Kubernetes Job替换操作
问题:用Python Kubernetes API实现Kubectl Job替换操作
我有如下kubectl命令:
kubectl get job <JOB-NAME> -o json | jq 'del(.spec.selector)' | jq 'del(.spec.template.metadata.labels)' | kubectl replace --force -f -
这条命令可以将现有Kubernetes Job替换为自身(删除指定字段后重新应用)。请问能否通过Python Kubernetes API实现同样的操作?
我当前尝试的代码如下:
import kubernetes from kubernetes import client, config # 加载kube配置 config.load_kube_config() configuration = kubernetes.client.Configuration() name = "job-1" namespace = "default" v1 = client.CoreV1Api() # 根据Job名称获取对应的Pod名称 metabase_create_readonly_user_name = '' pods = v1.list_namespaced_pod(namespace, label_selector='job-name={}'.format(name), watch=False) for pod in pods.items: job_name = pod.metadata.name # 这里无法正常工作! v1.replace_namespaced_pod(job_name, namespace)
但replace_namespaced_pod需要传入body参数,我不知道该传入什么内容。有没有办法获取现有Job的完整配置作为body传入,或者有其他正确的实现方式?
内容的提问来源于stack exchange,提问作者jipot
相关产品推荐
相关产品推荐

