I'm currently running a python script which has only a print statement.
print("Completed")
The python code will be deployed on kubernetes using Dockerfile and a Deployment YAML File.
Dockerfile:
FROM python:3.9
WORKDIR /app
COPY Test.py /app/Test.py
RUN python3 -m pip install --upgrade pip
ENTRYPOINT ["python"]
CMD ["Test.py"]
Deployment YAML File:
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-01
spec:
replicas: 1
selector:
matchLabels:
bb: web
template:
metadata:
labels:
bb: web
spec:
containers:
- name: test-01
image: testrepo/testingpy:latest
The pod will be created, will succesfully run and also show the reason for Termination is because it is Completed with exit code 0 (While exploring the description of the pod).
State: Waiting
Reason: CrashLoopBackOff
Last State: Terminated
Reason: Completed
Exit Code: 0
After a few seconds the pod will go into CrashLoopBackOff Warning State with the reason "Back-off restarting failed container". The logs for the pod gives information only if there is any printed statements or error while running the code.
kubectl logs etl-patient-c5d44fcc-scc9s --all-containers
Completed
The kubernetes pod has no reason to go into CrashLoopBackOff state. The pod must execute the script and stay as completed.
Changes Tried.
- Tried to manipulate the YAML file with restartPolicy: OnFailure but it raised an error while deploying.
- Tried with different python versions which also didn't change the outcome.
P.S The indentation of the YAML file is not visible properly but the indentation of the YAML file is correct.