gpt4 book ai didi

docker - 在 Kubernetes 上的 Docker 镜像中运行时,Gunicorn 不断引导工作人员

转载 作者:行者123 更新时间:2023-12-02 11:33:16 25 4
gpt4 key购买 nike

我已经对一个 Flask 应用程序进行了 docker 化,使用 gunicorn 为其提供服务。我的 Dockerfile 的最后一行是:

CMD source activate my_env && gunicorn --timeout 333 --bind 0.0.0.0:5000 app:app

在本地运行应用程序时——直接在我的控制台中,不使用 docker,或者使用

docker run -dit \
--name my-app \
--publish 5000:5000 \
my-app:latest

启动正常。我得到如下日志:

[2018-12-04 19:32:30 +0000] [8] [INFO] Starting gunicorn 19.7.1
[2018-12-04 19:32:30 +0000] [8] [INFO] Listening at: http://0.0.0.0:5000 (8)
[2018-12-04 19:32:30 +0000] [8] [INFO] Using worker: sync
[2018-12-04 19:32:30 +0000] [16] [INFO] Booting worker with pid: 16
<my app's output>

当在 k8s 中运行相同的图像时,我得到了

[2018-12-10 21:09:42 +0000] [5] [INFO] Starting gunicorn 19.7.1
[2018-12-10 21:09:42 +0000] [5] [INFO] Listening at: http://0.0.0.0:5000 (5)
[2018-12-10 21:09:42 +0000] [5] [INFO] Using worker: sync
[2018-12-10 21:09:42 +0000] [13] [INFO] Booting worker with pid: 13
[2018-12-10 21:10:52 +0000] [16] [INFO] Booting worker with pid: 16
[2018-12-10 21:10:53 +0000] [19] [INFO] Booting worker with pid: 19
[2018-12-10 21:14:40 +0000] [22] [INFO] Booting worker with pid: 22
[2018-12-10 21:16:14 +0000] [25] [INFO] Booting worker with pid: 25
[2018-12-10 21:16:25 +0000] [28] [INFO] Booting worker with pid: 28
<etc>

我的 k8s 部署 yaml 看起来像

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: my-deployment
spec:
replicas: 1
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
imagePullSecrets:
- name: regcred
containers:
- name: my-frontend
image: my-registry/my-frontend:latest
ports:
- containerPort: 80
- name: my-backend
image: my-registry/my-backend:latest
ports:
- containerPort: 5000

这里,有问题的容器是my-backend。知道为什么会这样吗?

更新:在我写这篇文章时,使用 kubectl describe pods 打印的事件列表已更新如下:

Warning  FailedMount            9m55s                  kubelet, minikube  MountVolume.SetUp failed for volume "default-token-k2shm" : Get https://localhost:8443/api/v1/namespaces/default/secrets/default-token-k2shm: net/http: TLS handshake timeout
Warning FailedMount 9m53s (x2 over 9m54s) kubelet, minikube MountVolume.SetUp failed for volume "default-token-k2shm" : secrets "default-token-k2shm" is forbidden: User "system:node:minikube" cannot get secrets in the namespace "default": no path found to object
Normal SuccessfulMountVolume 9m50s kubelet, minikube MountVolume.SetUp succeeded for volume "default-token-k2shm"

不确定它是否与我的问题相关

最佳答案

我通过在容器下添加资源来解决这个问题——我需要更多内存。

resources:
requests:
memory: "512Mi"
cpu: 0.1
limits:
memory: "1024Mi"
cpu: 1.0

希望对您有所帮助。

关于docker - 在 Kubernetes 上的 Docker 镜像中运行时,Gunicorn 不断引导工作人员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53714029/

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