【问题标题】:Create a pod using kubernetes SDK for python使用 kubernetes SDK for python 创建一个 pod
【发布时间】:2020-09-17 01:30:06
【问题描述】:

我想使用 python 客户端 SDK(类似于 kubectl run)创建一个 pod,结果如下:

kubectl run --rm --image $IMAGE --overrides="$OVERRIDES" --generator=run-pod/v1 -ti "$POD"

有什么好的例子吗?我可以看到一些使用 exec https://github.com/kubernetes-client/python/blob/master/examples/pod_exec.py 的示例,但这需要先创建 pod 并运行 exec,但不会像 kubectl run 中的 -ti 标志那样运行 "Interactive Terminal"

以下代码仅适用于发送远程命令,但不适用于交互式终端,即使我们运行 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")

【问题讨论】:

  • 为什么需要交互式终端;你能把你想让豆荚做的事情变成它的command:吗?您在问题中包含的图片是什么?
  • 正在构建一个需要交互式终端的故障排除脚本。运行一组命令不是我想要的。

标签: python python-3.x kubernetes kubernetes-python-client


【解决方案1】:

我使用伪终端让它在这里工作。退出终端后仍有一些问题。

我让它在这里工作。退出终端后仍有一些问题。 https://github.com/mohatb/python/blob/master/examples/exec_tty

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-11-27
    • 1970-01-01
    • 2020-09-13
    • 2019-08-02
    • 1970-01-01
    • 2019-08-11
    • 2016-02-04
    • 2015-09-01
    相关资源
    最近更新 更多