在Kubernetes上的Docker映像中运行时

在Kubernetes上的Docker映像中运行时

本文介绍了在Kubernetes上的Docker映像中运行时,Gunicorn会不断引导工作人员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用Flanicorn为其提供了一个Flask应用的泊坞窗。我的Dockerfile的最后一行是:

I've dockerized a Flask app, using gunicorn to serve it. The last line of my Dockerfile is:

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

在本地运行应用程序时–直接在我的控制台中,没有docker,或

When running the app locally – either straight in my console, without docker, or with

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

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

It boots up fine. I get a log like:

[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 中运行同一图像时得到

When running the same image in k8s I get

[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看起来像

My k8s deployment yaml looks like

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 。任何想法为什么会发生这种情况?

Here, the container in question is my-backend. Any ideas why this is happening?

更新:在我撰写本文时,用 kubectl打印的事件列表描述了豆荚已更新为以下内容:

Update: As I wrote this, the events list that is printed with kubectl describe pods was updated with the following:

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"

不成功确定是否与我的问题有关

Not sure if it's relevant to my issue

推荐答案

我解决了d通过在容器下添加资源-我的需要更多的内存。

I solved this by adding resources under the container - mine needed more memory.

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

希望有帮助。

这篇关于在Kubernetes上的Docker映像中运行时,Gunicorn会不断引导工作人员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 04:18