如何使用kubernetes和skaffold调试python代码? [英] How do you debug python code with kubernetes and skaffold?

查看:157
本文介绍了如何使用kubernetes和skaffold调试python代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am currently running a django app under python3 through kubernetes by going through skaffold dev. I have hot reload working with the Python source code. Is it currently possible to do interactive debugging with python on kubernetes?

例如,

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

通常,在容器外部,碰到端点将使我进入(pdb) shell.

Usually, outside a container, hitting the endpoint will drop me in the (pdb) shell.

在当前设置中,我在Deployment文件中将stdintty设置为true.该代码确实在断点处停止,但是它无法让我访问(pdb) shell.

In the current setup, I have set stdin and tty to true in the Deployment file. The code does stop at the breakpoint but it doesn't give me access to the (pdb) shell.

推荐答案

有一个kubectl命令,允许您

There is a kubectl command that allows you to attach to a running container in a 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才能使用调试器,因此以下文章可能会有所帮助:

It should allow you to interact with the debugger in the container. Probably you may need to adjust your pod to use a debugger, so the following article might be helpful:

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

There is also telepresence tool that helps you to use different approach of application debugging:

使用 telepresence ,您可以将自定义工具(例如调试器和IDE)用于本地服务,并为该服务提供对ConfigMap,密钥以及在远程群集上运行的服务的完全访问权限.

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.

使用--swap-deployment选项将现有部署与网真代理交换.交换可让您在本地运行服务并连接到远程Kubernetes集群.远程群集中的服务现在可以访问本地运行的实例.

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.

这篇关于如何使用kubernetes和skaffold调试python代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆