gpt4 book ai didi

python - 如何使用 kubernetes 和 skaffold 调试 python 代码?

转载 作者:太空狗 更新时间:2023-10-30 02:51:40 25 4
gpt4 key购买 nike

我目前通过 skaffold dev 通过 kubernetes 在 python3 下运行一个 django 应用程序。我使用 Python 源代码进行热重载。目前是否可以在 kubernetes 上使用 python 进行交互式调试?

例如,

def index(request):
import pdb; pdb.set_trace()
return render(request, 'index.html', {})

通常,在容器外,点击端点将使我进入 (pdb) shell。

在当前设置中,我在Deployment 文件中将stdintty 设置为true。代码确实在断点处停止,但它不允许我访问 (pdb) shell。

最佳答案

有一个 kubectl 命令可以让你 attach到 pod 中正在运行的容器:

kubectl attach <pod-name> -c <container-name> [-n namespace] -i -t

-i (default:false) Pass stdin to the container
-t (default:false) Stdin is a TTY

它应该允许您与容器中的调试器进行交互。可能您可能需要调整您的 pod 以使用调试器,因此以下文章可能会有所帮助:

还有telepresence帮助您使用不同的应用程序调试方法的工具:

Using telepresence allows you to use custom tools, such as a debugger and IDE, for a local service and provides the service full access to ConfigMap, secrets, and the services running on the remote cluster.

Use the --swap-deployment option to swap an existing deployment with the Telepresence proxy. Swapping allows you to run a service locally and connect to the remote Kubernetes cluster. The services in the remote cluster can now access the locally running instance.

关于python - 如何使用 kubernetes 和 skaffold 调试 python 代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54874683/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com