Kubernetes Job provide json file input

10/19/2021

I have to run Kubernetes job, Only One pod and one time execution (No Parallel pods are needed). Terminate Job once task is done.

My application is developed using python, this is how i am running manually

python3 app.py -input-file big_file_config.json -run_type job

My job file:

apiVersion: batch/v1
kind: Job
metadata:
  name: loader-triiger
spec:
  backoffLimit: 5
  activeDeadlineSeconds: 60000
  template:
    spec:
      containers:
        - name: loader-triiger
          image: ""
          command: ["appy.py", "-input-file", "big_file_config.json", "-run_type", "job"] # how to pass inputfile to kubernetes job pod
          imagePullPolicy: Always
          resources:
            limits:
              memory: "16048Mi"
              cpu: "16000m"
         
      restartPolicy: Never

Dockerfile:

FROM python:3.8-slim-buster

WORKDIR /app

COPY requirements.txt requirements.txt
RUN pip3 install -r requirements.txt

COPY . .

# run Application
ENTRYPOINT ["python3"]

I can upload json input file directly to docker image, but image size increases and also, each time input chnages need to build a docker image.

so it is great to provide option that support command line arrguments to accept input file to kuberenets job pod. Any help greatly appreciated

-- Vidya
containers
devops
docker
kubernetes
linux

1 Answer

10/19/2021

You could use configmap to achieve this.

  1. Create a configmap with the content of your config file.
  2. Make the pod use that configmap, and populate a volume inside the pod with the data stored in ConfigMap
  3. Change the entrypoint of your image to get the config file from the above directory.
-- Manish Joshi
Source: StackOverflow