Skip to main content
 首页 » 编程设计

docker之Kubernetes 如何调用 Docker 镜像

2025年05月04日307kerrycode

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