2

I am new to Kubernetes and I have a simple python code which is a sum of two numbers and deployed in Kubernetes.
I want to pass two values dynamically to Kubernetes running container. My Code:

import sys

number1 = int(sys.argv[1])

number2 = int(sys.argv[2])

print(number1 + number2)

I want to pass number 1 and number 2 dynamically each time with different numbers.
Can anyone help me here?

Salim Djerbouh
  • 10,719
  • 6
  • 29
  • 61
ramesh
  • 21
  • 2

1 Answers1

0

In your pod spec field there are fields to pass in arguments to your command. If you are using a different type of kubernetes kind (deployment, daemonset ...) that kind has a template field for your pod spec. This document has a good description of what you are trying to do.

In short you need to provide an argument field to your pods spec.

spec:
  containers:
  - name: your-containers-name
    image: image
    command: ["python", "app.py"]
    args: 
      - "234" # number1
      - "433" # number2
BBS
  • 1,351
  • 2
  • 12
  • 27
  • If I want to change values from 234 to something else, Again do i need to edit pods spec. Is there a way to pass those changes dynamically from command line – ramesh Sep 22 '19 at 06:39
  • You can do something like this https://stackoverflow.com/a/56009991/2430915, or use sed to update the yaml before piping it to kubectl. The other option you could use is the `kubectl run` command which might look something like this `kubectl run nginx --image=nginx -- ... ` – BBS Sep 22 '19 at 22:46