Home > Mobile >  Print/Return python app docker image output in AWS EKS without using flask
Print/Return python app docker image output in AWS EKS without using flask

Time:06-23

Here, I have a python file with the name main.py that I want to execute.

The main.py file contains:

import time
import sys
def hello():
    for i in range(10):
         print(“\n”*4, “Hello from AMAN!”, “\n”*4)
         time.sleep(2)
sys.exit(0)
if __name__ == “__main__”:
     hello()

and I have created a docker image with name Docker file

FROM python:3.7
RUN mkdir /app
WORKDIR /app
ADD . /app/
RUN pip install -r requirements.txt
CMD [“python”, “/app/main.py”]

I want to know that is there any way to run the python-app image on AWS EKS cluster in pods and get the output “Hello from AMAN!” (whatever this code prints ) back to my system / print it in console .

Since I am not using flask I cannot see the application on web browser so this app will run in pods ,but I am not able to figure out how to get the output back to the terminal /SSH or in form of some file .

Please Help me in finding a way to get the output of app running back without using any web framework like flask /node etc .

CodePudding user response:

You can use the command

kubectl logs <POD name>

it show you the output.

If POD running on an EKS you can use different ways to get the logs, write to file, push logs to AWS cloud watch other external logging systems like ELK, using kubectl check logs.

K8s by default store container logs stdin and stdout

  • Related