简体   繁体   English

在Kubernetes上调试Python

[英]Debug Python on Kubernetes

Current Architecture 当前架构

On the most foundation part is Kubernetes with multiple different container images. 最基础的部分是带有多个不同容器映像的Kubernetes。

On top of them, we have a python library which dynamically loads our code, which we write and install on those containers after deployment. 在它们之上,我们有一个python库,可动态加载我们的代码,我们在部署后将这些代码编写并安装在这些容器上。 We write stateful applications on k8, that's why this kind of architecture. 我们在k8上编写有状态的应用程序,这就是这种架构的原因。

Let's call our code beta and the lib which loads it alpha 让我们将代码称为beta和将其加载为alpha

The current process testing new changes it the following: 当前测试新过程的过程对其进行了以下更改:

  • provision of a new container with the new installed changed from the artefactory 提供了带有新安装容器的新容器
  • run alpha , which loads beta , which we actively develop 运行alpha ,加载beta ,我们会积极开发

What we can do/ cannot do 我们能做/不能做的

  • no ssh 没有SSH
  • all commands of kubectl kubectl的所有命令
  • port forwards 港口前锋
  • im using OSX, with PyCharm 我正在使用OSX和PyCharm

Now the question: 现在的问题是:

  • How can I start my local IDE and set a breakpoint in beta , which gets loaded after running alpha on the k8 pod -> container 我如何启动我的本地IDE并在beta设置一个断点,在k8 pod->容器上运行alpha之后,该断点将被加载

For now the possible solution was to do the following: - add a remote debugger to the code, which listens upon start - port forward the traffic - clone the code (install), such that the lib gets run, as soon as you run the main - run the code - it waits until attach - attach to the debugger. 现在,可能的解决方案是执行以下操作:-在代码中添加一个远程调试器,该调试器在启动时进行侦听-端口转发流量-克隆代码(安装),以便库在运行时立即运行main-运行代码-等待连接-附加到调试器。

Voila it works. 瞧,它有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM