Setting up the Python Application

This entry is part 4 of 11 in the series Kubernetes and everything else

To start the Python application we need to have Python3 and Pip installed (their environment variables need to be set up as well).

Installing Dependencies

Navigate in the CMD to the directory sa-logic/sa (repo) and type the following command:

$ python -m pip install -r requirements.txt
$ python -m textblob.download_corpora

Starting the app

Pip installs the dependencies and we are ready to start the application by executing the following command:

* Running on http://localhost:5000/ (Press CTRL+C to quit)

Which means that our application is running and listening for HTTP Requests at the port 5000 on localhost.

Inspecting the Code

Let’s investigate the code to understand what is happening in the SA Logic python application.

  1. Instantiate a Flask object.
  2. Defines the path at which a POST request can be made.
  3. Extract the “sentence” property from the request body.
  4. Instantiate an anonymous TextBlob object and get the polarity from the first sentence. (We have only one).
  5. Return the response with the body containing the sentence and the polarity to the caller.
  6. Run the flask object app to listen for requests on localhost:5000.

The services are set up to communicate with each other, give them a try before continuing on!

Fig. 1. Microservice architecture set up

Let’s recapitulate what we did; We started all the microservices running in different ports, we configured each to communicate with each other, and this was a tedious process, but it worked, so why Kubernetes you ask? Because our application is not scalable, it’s not resilient and not maintainable. Stay tuned as in the next article, we will go over how to start the services in Docker Containers, as it is a prerequisite to being able to run them in Kubernetes Cluster.

Container-ization of the Services >>
If you enjoyed the article, please share and comment below!