docker - Kubernetes 如何调用 Docker 镜像?

标签 docker flask kubernetes uwsgi google-kubernetes-engine

我正在尝试在 Kubernetes 部署中通过 uWSGI 运行 Flask 应用程序。当我在本地运行 Docker 容器时,一切似乎都运行良好。但是,当我在 Google Kubernetes Engine 上创建 Kubernetes 部署时,部署进入 Crashloop Backoff,因为 uWSGI 提示:
uwsgi: unrecognized option '--http 127.0.0.1:8080' .

该图像肯定具有 http 选项,因为: a. uWSGI was installed via pip3 which includes the http plugin. b. When I run the deployment with --list-plugins, the http plugin is listed. c. The http option is recognized correctly when run locally.
我在本地运行 Docker 镜像:
$: docker run <image_name> uwsgi --http 127.0.0.1:8080
容器 Kubernetes YAML 配置是:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  labels:
    app: launch-service-example
  name: launch-service-example
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: launch-service-example
    spec:
      containers:
        - name: launch-service-example
          image: <image_name>
          command: ["uwsgi"]
          args:
            - "--http 127.0.0.1:8080"
            - "--module code.experimental.launch_service_example.__main__"
            - "--callable APP"
            - "--master"
            - "--processes=2"
            - "--enable-threads"
            - "--pyargv --test1=3--test2=abc--test3=true"
          ports:
            - containerPort: 8080
---
kind: Service
apiVersion: v1
metadata:
  name: launch-service-example-service
spec:
  selector:
    app: launch-service-example
  ports:
  - protocol: TCP
    port: 8080
    targetPort: 8080

容器完全相同,这让我相信 Kubernetes 调用容器的方式可能会导致问题。作为旁注,我尝试通过没有参数的命令列表传递所有参数,这会导致相同的结果。任何帮助将不胜感激。

最佳答案

这是由于控制台和配置中的参数处理之间的差异而发生的。

要修复它,只需像这样拆分您的参数:

args:
  - "--http"
  - "127.0.0.1:8080"
  - "--module code.experimental.launch_service_example.__main__"
  - "--callable"
  - "APP"
  - "--master"
  - "--processes=2"
  - "--enable-threads"
  - "--pyargv"
  - "--test1=3--test2=abc--test3=true"

关于docker - Kubernetes 如何调用 Docker 镜像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49800347/

相关文章:

windows - 从 Windows 访问 Docker 容器文件

docker - Kibana 未连接到 Elasticsearch ( ["warning","elasticsearch","admin"] ,"pid":12 ,"message" :"No living connections"})

python-2.7 - 使用 jinja2 生成随机数

python - 将 Docker 中的 Flask 应用程序暴露到 Internet

kubernetes - 为什么不推荐多区域 Kubernetes 部署?

kubernetes - 我应该更喜欢 Kustomize 而不是 Helm

node.js - 限制 Docker 容器的文件访问

docker - 按需启动容器

python - pip install sqlalchemy-migrate 莫名崩溃烧毁

amazon-web-services - 如何在 kubernetes 中将 SSL 证书安装到 aws 负载均衡器?