我想用python客户端SDK创建一个pod(类似于kubectl运行),它会给出如下结果:
kubectl run --rm --image $IMAGE --overrides="$OVERRIDES" --generator=run-pod/v1 -ti "$POD"
有好的例子吗?我可以看到一些使用exechttps://github.com/kubernetes-client/python/blob/master/examples/pod_exec.py的示例,但这需要首先创建pod并运行exec,但不运行“Interactive Terminal”作为kubectl run中的-ti标志
下面的代码仅适用于发送远程命令,而不适用于交互式终端,即使我们运行command=['/bin/bash'],其输出如下所示
try:
#resp = stream(api_instance.connect_post_namespaced_pod_exec, podname, namespace='default', stderr=True, stdin=True, stdout=True, tty=True)
stream(api_instance.connect_get_namespaced_pod_exec, podname, namespace='default', stderr=True, stdin=False, stdout=True, tty=False)
except ApiException as e:
print("Exception when calling CoreV1Api->connect_get_namespaced_pod_exec: %s\n" % e)
print(f"Pod created - cannot exec")
我用伪终端实现了这一点。退出终端后仍有一些问题
我让它在这里工作。退出终端后仍有一些问题。 https://github.com/mohatb/python/blob/master/examples/exec_tty
相关问题 更多 >
编程相关推荐