简体   繁体   English

Kubernetes 容器参数行为不正确

[英]Kubernetes container args behave incorrect

I want to use Kubernetes and the postman/newman Docker image to execute my API tests.我想使用 Kubernetes 和postman/newman新人 Docker 图像来执行我的 API 测试。

Locally, I can execute the image with在本地,我可以执行图像

docker run postman/newman run <url-to-collection> --env-var baseUrl=<local-hostname> docker 运行 postman/newman 运行 <url-to-collection> --env-var baseUrl=<local-hostname>

I include the Image in a Kubernetes manifest file我将图像包含在 Kubernetes 清单文件中

spec:
  containers:
    - name: newman
      image: postman/newman:latest
      args:
        - run
        - '<url-to-collection>'
        - --env-var baseUrl=<kubernetes-hostname>

When I apply the manifest and look at the logs of the container, I get the following error:当我应用清单并查看容器的日志时,我收到以下错误:

error: unknown option '--global-var baseUrl=<kubernetes-hostname>'

I tried out many things with quotes and using the command section instead of the args section, but always with the same result.我用引号尝试了很多东西,并使用command部分而不是args部分,但总是得到相同的结果。 I figure that Kubernetes somehow builds the command in a way, that the newman executable can not understand it.我认为newman以某种方式构建命令,纽曼可执行文件无法理解它。 However I could not find any info about that.但是我找不到任何有关此的信息。

(I also created an issue in the GitHub repo of Newman here ) (我还在 Newman 的 GitHub 存储库中创建了一个问题

Could anybody explain to me where this problem comes from and how I might solve this?任何人都可以向我解释这个问题来自哪里以及我如何解决这个问题?

Thanks anyways!不管怎么说,多谢拉!

Linux commands are made up of a sequence of words. Linux 命令由一系列字组成。 If you type a command at a shell prompt, it takes responsibility for splitting it into words for you, but in the Kubernetes args: list, you need to split out the words yourself.如果您在 shell 提示符处键入命令,它负责为您将其拆分为单词,但在 Kubernetes args:列表中,您需要自己拆分单词。

args:
  - run
  - '<url-to-collection>'
  # You want these as two separate arguments, so they need to be
  # two separate list items
  - --env-var
  - baseUrl=<kubernetes-hostname>

If the two arguments are in the same list item, they are a single "word":如果两个 arguments 在同一个列表项中,则它们是一个“单词”:

# /bin/ls "/app/some directory/some file"
command:
  - /bin/ls
  # a single argument, including embedded spaces
  - /app/some directory/some file

The same basic rules apply for Docker Compose entrypoint: and command: and the JSON-syntax Dockerfile ENTRYPOINT and CMD directives, except that the Docker-native forms all also accept a plain string that they will split on spaces (using a shell in the Dockerfile case, but not in the Compose case). The same basic rules apply for Docker Compose entrypoint: and command: and the JSON-syntax Dockerfile ENTRYPOINT and CMD directives, except that the Docker-native forms all also accept a plain string that they will split on spaces (using a shell in the Dockerfile情况下,但不是在 Compose 情况下)。

In the docker run command you provide, the shell on your host system processes it first, so the --env-var option and baseUrl=... argument get split into separate words before they're passed into the container.在您提供的docker run命令中,主机系统上的 shell 首先处理它,因此--env-var选项和 baseUrl baseUrl=...参数在传递到容器之前被拆分为单独的单词。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM