我在 kubernetes pod.How 的容器中有一个 python 脚本 运行 我要停止与 pod 启动一起运行的脚本吗?
I have a python script running inside a container of kubernetes pod.How do i stop the script which runs along with the starting of the pod?
我 运行 在 Kubernetes pod 的容器内设置两个线程,一个线程将一些数据推送到 db,另一个线程(flask 应用程序)显示来自数据库的数据。所以一旦 pod 启动 main.py(启动上面提到的两个线程)就会被调用。
Docker 文件:
FROM python:3
WORKDIR /usr/src/app
COPY app/requirements.txt .
RUN pip install -r requirements.txt
COPY app .
CMD ["python3","./main.py"]
我有两个问题:
日志是查看 运行ning 脚本输出的唯一途径吗?当它在终端上 运行 时,我们不能连续看到它的输出吗?
此外,我无法通过进入容器来 运行 相同的 main.py 文件。它抛出以下错误:
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/local/lib/python3.9/threading.py", line 954, in _bootstrap_inner
self.run()
File "/usr/local/lib/python3.9/threading.py", line 892, in run
self._target(*self._args, **self._kwargs)
File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 920, in run
run_simple(t.cast(str, host), port, self, **options)
File "/usr/local/lib/python3.9/site-packages/werkzeug/serving.py", line 1008, in run_simple
inner()
File "/usr/local/lib/python3.9/site-packages/werkzeug/serving.py", line 948, in inner
srv = make_server(
File "/usr/local/lib/python3.9/site-packages/werkzeug/serving.py", line 780, in make_server
return ThreadedWSGIServer(
File "/usr/local/lib/python3.9/site-packages/werkzeug/serving.py", line 686, in __init__
super().__init__(server_address, handler) # type: ignore
File "/usr/local/lib/python3.9/socketserver.py", line 452, in __init__
self.server_bind()
File "/usr/local/lib/python3.9/http/server.py", line 138, in server_bind
socketserver.TCPServer.server_bind(self)
File "/usr/local/lib/python3.9/socketserver.py", line 466, in server_bind
self.socket.bind(self.server_address)
OSError: [Errno 98] Address already in use (edited)
如何停止与 pod 一起启动的 main.py
脚本并能够直接从容器本身 运行 main.py?
谢谢。
错误信息说的都是:
OSError: [Errno 98] Address already in use (edited)
您的 python 脚本似乎尝试打开同一个端口两次。你不能这样做。检查您的代码并修复它。
现在回答你的另一个问题:
Is logs the only way to see the output of the running script? Can't we see its output continuously as it runs on the terminal?
运行 kubectl logs -f
将跟随日志,这应该让您在终端中运行时连续看到输出。
我 运行 在 Kubernetes pod 的容器内设置两个线程,一个线程将一些数据推送到 db,另一个线程(flask 应用程序)显示来自数据库的数据。所以一旦 pod 启动 main.py(启动上面提到的两个线程)就会被调用。
Docker 文件:
FROM python:3
WORKDIR /usr/src/app
COPY app/requirements.txt .
RUN pip install -r requirements.txt
COPY app .
CMD ["python3","./main.py"]
我有两个问题:
日志是查看 运行ning 脚本输出的唯一途径吗?当它在终端上 运行 时,我们不能连续看到它的输出吗?
此外,我无法通过进入容器来 运行 相同的 main.py 文件。它抛出以下错误:
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/local/lib/python3.9/threading.py", line 954, in _bootstrap_inner
self.run()
File "/usr/local/lib/python3.9/threading.py", line 892, in run
self._target(*self._args, **self._kwargs)
File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 920, in run
run_simple(t.cast(str, host), port, self, **options)
File "/usr/local/lib/python3.9/site-packages/werkzeug/serving.py", line 1008, in run_simple
inner()
File "/usr/local/lib/python3.9/site-packages/werkzeug/serving.py", line 948, in inner
srv = make_server(
File "/usr/local/lib/python3.9/site-packages/werkzeug/serving.py", line 780, in make_server
return ThreadedWSGIServer(
File "/usr/local/lib/python3.9/site-packages/werkzeug/serving.py", line 686, in __init__
super().__init__(server_address, handler) # type: ignore
File "/usr/local/lib/python3.9/socketserver.py", line 452, in __init__
self.server_bind()
File "/usr/local/lib/python3.9/http/server.py", line 138, in server_bind
socketserver.TCPServer.server_bind(self)
File "/usr/local/lib/python3.9/socketserver.py", line 466, in server_bind
self.socket.bind(self.server_address)
OSError: [Errno 98] Address already in use (edited)
如何停止与 pod 一起启动的 main.py
脚本并能够直接从容器本身 运行 main.py?
谢谢。
错误信息说的都是:
OSError: [Errno 98] Address already in use (edited)
您的 python 脚本似乎尝试打开同一个端口两次。你不能这样做。检查您的代码并修复它。
现在回答你的另一个问题:
Is logs the only way to see the output of the running script? Can't we see its output continuously as it runs on the terminal?
运行 kubectl logs -f
将跟随日志,这应该让您在终端中运行时连续看到输出。