What is the best way to run simple kubernetes job?

1/21/2019

I want to run a kubernetes job which runs some python code and dies.

The job will run only in master node.

I want this job to be light and fast.

I think there can be some ways to do this,

  1. Make a Dockerfile that contains (python, pip packages I need, and python source code).

    • With this, I have to manage Dockerfile only, but is it OK if I manage Dockerfile and source code at the same time?
  2. Make a Dockerfile that contains (python, pip packages I need), and run container with python source code mounted with -v option.

    • With this, I always have to get up-to-date source code on master node.
  3. Make a Dockerfile that contains (python, pip packages I need, and getting python source code from my git repository).

    • I think this is the best way in terms of version management, but it could be slower than ways above.

Can you give me some advise about this concern?

Or there is better way?

-- Cherryade
kubernetes
python

1 Answer

1/21/2019

You have provided the solution to your issue in the title of the question. What you want to achieve is just the definition of the Kubernetes Job.

A job creates one or more pods and ensures that a specified number of them successfully terminate. As pods successfully complete, the job tracks the successful completions. When a specified number of successful completions is reached, the job itself is complete.

You can use predefined python container. Just as presented in the documentation but with pearl. Or you can build your own docker image. You can use private registry for that. I don't know the reason you want to run the pod on the master. I advise you first check this topic so you know the yes and no's. Then for versioning you can create new jobs or just update the docker image as you have noted in the question.

Hope this is what you were looking for, if not it could be better to add some more details about what that job is supposed to do so I could get context for better answer.

-- aurelius
Source: StackOverflow