I am trying to execute a python program as a background process inside a container with kubectl as below (kubectl issued on local machine):

我试图在一个容器内执行一个python程序作为后台进程,如下所示kubectl(在本地机器上发布kubectl):

kubectl exec -it -- bash -c "cd some-dir && (python xxx.py --arg1 abc &)"

kubectl exec -it - bash -c“cd some-dir &&(python xxx.py --arg1 abc&)”

When I login to the container and check "ps -ef" I do not see this process running. Also there is no output from kubectl command itself.

当我登录容器并检查“ps -ef”时,我没有看到此进程正在运行。此外,kubectl命令本身没有输出。

Is the kubectl command issued correct?.

kubectl命令发出正确吗?

Is there a better way to achieve the same?

有没有更好的方法来实现同样的目标?

How can I see the output/logs printed of the background process being run?

如何查看正在运行的后台进程的输出/日志?

If I need to stop this background process after some duration, what is the best way to do this?

如果我需要在一段时间后停止此后台进程,那么最好的方法是什么?

Thanks

2 个解决方案

#1


0

Actually, the best way to make this kind of things is adding an entry point to your container and run execute the commands there. Like:

实际上,制作这类东西的最好方法是在容器中添加一个入口点并运行那里的命令。喜欢:

entrypoint.sh:

#!/bin/bash
set -e

cd some-dir && (python xxx.py --arg1 abc &)
./somethingelse.sh

exec "$@"

You wouldn't need to go manually inside every single container and run the command.

您不需要在每个容器内手动运行并运行该命令。

更多相关文章

  1. Python脚本——连接到SSH并运行命令
  2. conda不是内部或者外部命令
  3. 在python中复制命令的正确方法[复制]
  4. 基础入门_Python-进线协程.分分钟玩转multiprocessing多进程编程
  5. python使用多进程爬取图片
  6. pip常用命令汇总
  7. pip常用命令、配置pip源
  8. Python随心记--进程、线程
  9. 我需要一个django-芹菜守护进程来监听特定的rabbitmq通道

随机推荐

  1. Android文件相关:RandomAccessFile介绍与
  2. Android(安卓)ClassLoader
  3. Android(安卓)Support V4, V7, V13的作用
  4. [置顶] android ANR
  5. Android(安卓)Studio下Ndk开发踩过的坑以
  6. android 数据存储之 SharedPreference
  7. Android实践之ScrollView中滑动冲突处理
  8. 2016总结+2017计划
  9. XposedHook:hook敏感函数
  10. Android(安卓)反编译