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?
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