本文介绍了如何在kubernetes中传递命令行参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

需要为docker容器appContainer1&传递命令行参数pod.yaml中的appContainer2.

Need to pass command line arguments for the docker containers appContainer1 & appContainer2 in the pod.yaml.

pod.yaml

apiVersion: v1
kind: Pod
metadata:
  name: microservices
  labels:
    app: apps
spec:
  containers:
    - name: appContainer1
      image: gcr.io/mybucket/appContainerImage1
      ports:
        - containerPort: 8080
    - name: appContainer2
      image: b.gcr.io/mybucket/appContainerImage2
      ports:
        - containerPort: 9090

在docker中,我可以通过环境变量(-e)传递命令行参数

In docker, I can pass the command line arguments via environment variable(-e)

docker run --rm -it -p 9090:9090 -e spring.profiles.dynamic=local applicationimage1

类似地,当容器在kubernetes中运行时,我需要传递命令行参数.

Similarly, I need to pass command line arguments when the containers run inside kubernetes.

推荐答案

听起来您实际上并不需要命令行参数,但是需要环境变量-您可以使用env来实现:

It sounds like you don't actually want command line arguments, but environment variables - and you can use env for that:

- name: appContainer1
  image: gcr.io/mybucket/appContainerImage1
  ports:
    - containerPort: 8080
  env:
    - name: spring.profiles.dynamic
      value: local

可以使用命令行参数:

- name: appContainer1
  image: gcr.io/mybucket/appContainerImage1
  ports:
    - containerPort: 8080
  args:
    - foo
    - bar
    - "String containing:colons:"

这篇关于如何在kubernetes中传递命令行参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-05 17:46