Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass command line arguments in kubernetes?

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

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

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

like image 455
Shiva Avatar asked Dec 12 '15 10:12

Shiva


People also ask

How do you pass command line arguments in Kubernetes?

To define arguments for the command, include the args field in the configuration file. The command and arguments that you define cannot be changed after the Pod is created. The command and arguments that you define in the configuration file override the default command and arguments provided by the container image.

Can I command in Kubernetes?

kubectl provides the auth can-i subcommand for quickly querying the API authorization layer. The command uses the SelfSubjectAccessReview API to determine if the current user can perform a given action, and works regardless of the authorization mode used.

Is a command line utility to interact with Kubernetes?

The Kubernetes command-line tool, kubectl, allows you to run commands against Kubernetes clusters. You can use kubectl to deploy applications, inspect and manage cluster resources, and view logs. For more information including a complete list of kubectl operations, see the kubectl reference documentation.


1 Answers

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

You can use command line arguments:

- name: appContainer1 
  image: gcr.io/mybucket/appContainerImage1 
  ports:
    - containerPort: 8080
  args:
    - foo
    - bar
    - "String containing:colons:"
like image 51
Jon Skeet Avatar answered Oct 22 '22 03:10

Jon Skeet