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,
Make a Dockerfile that contains (python, pip packages I need, and python source code).
Make a Dockerfile that contains (python, pip packages I need), and run container with python source code mounted with -v option.
Make a Dockerfile that contains (python, pip packages I need, and getting python source code from my git repository).
Can you give me some advise about this concern?
Or there is better way?
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.