KubernetesPodOperator launches a Kubernetes pod that runs a container as specified in the operator's arguments.
First Example
In the first example, the following happens:
- KubernetesPodOperator instructs K8s to lunch a pod and prepare to run a container in it using the python image (the
image
parameter) from hub.docker.com (the default image registry)
- ENTRYPOINT of the python image is replaced by
["python", "somescript.py" "-c"]
(the cmd
parameter)
- CMD of the python image is replaced by
["print('HELLO')"]
(the arguments
parameter)
- ...
- The container is run
So, the complete command that is run in the container is
python somescript.py -c print('HELLO')
Obviously, the official Python image from Docker Hub does not have somescript.py
in its working directory. Even if did, it probably would have been not the one that you wrote. That is why the command fails with something like:
python: can't open file 'somescrit.py': [Errno 2] No such file or directory
Second Example
In the second example, pretty much the same happens as in the first example, but the command that is run in the container (again based on the cmd
and arguments
parameters) is
python somescript.py -c None
(None
is the string representation of the load_users_into_table()
's return value)
This command fails, because of the same reasons as in the first example.
How It Could be Done (a Sketch)
You could build a Docker image with somescript.py
and all its dependencies. Push the image to an image registry. Specify the image, ENTRYPOINT, and CMD in the corresponding parameters of KubernetesPodOperator.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…