Kubernetes 如何调用 Docker 图像?

How does Kubernetes invoke a Docker image?

我正在尝试通过 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"