- Introduction and Application Architecture
- Setting up the React Application
- Setting up the Spring WebApplication
- Setting up the Python Application
- Container-ization of the Services
- Container-ization of everything else
- Introduction to Kubernetes
- Kubernetes in Practice – Pods
- Kubernetes in Practice – Services
- Kubernetes in Practice – Deployments
- Kubernetes and everything else in Practice
- Kubernetes Volumes – in Practice
Let’s continue where we left off, creating the Images for the Java and Python Applications. And then we will verify that everything works together as shown in the figure below:
Containerizing the Java Application
Guess what! You learned almost everything about creating container Images! That’s why this part is extremely short.
Open the Dockerfile in sa-webapp, and you will find only two new keywords:
ENV SA_LOGIC_API_URL http://localhost:5000 … EXPOSE 8080
The keyword ENV declares an Environment Variable inside the docker container, which will enable us to provide the URL for the Sentiment Analysis API when starting the Container.
Additionally, the keyword EXPOSE exposes a port that we want to access later on. But hey!!! We didn’t do that in the Dockerfile in SA-Frontend, Good catch! This is for documentation purposes only, also it will serve as information to the person reading the Dockerfile.
You should be familiar with building and pushing the container image, but by any difficulties read up the README.md file in sa-webapp directory.
Containerizing the Python Application
In the Dockerfile in sa-logic there are no new keywords. Now you can call yourself a Docker-Master 😉
For building and pushing the container image read up the README.md in sa-logic directory.
Testing the Docker-ized Application
Can you trust something that you didn’t test? Neither can I. Let’s give these containers a test.
- Run the sa-logic container and configure to listen on port 5050:
$ docker run -d -p 5050:5000 $DOCKER_ID_USER/sentiment-analysis-logic
- Run the sa–webapp container and configure to listen on port 8080, and additionally we need to change the port in which the python app listens by overriding the environment variable SA_LOGIC_API_URL.
$ docker run -d -p 8080:8080 -e SA_LOGIC_API_URL='http://<container_ip or docker machine ip>:5000' $DOCKER_USER_ID/sentiment-analysis-web-app
Check out the README on how to get the container ip or docker machine ip.
- Run sa-frontend container:
$ docker run -d -p 80:80 $DOCKER_ID_USER/sentiment-analysis-frontend
We are done. Open your browser on url localhost:80.
Attention: If you changed the port for the sa-webapp, or if you are using docker-machine ip, you need to update App.js file in sa-frontend in the method analyzeSentence to fetch from the new IP or Port, and then you need to build, push and pull the updated image.
Why Kubernetes?
We can see that the application is working, And it is containerized, so why Kubernetes? We will investigate deeper into that in the next article, but I want to leave you a brainteaser.
- Our Sentiment Analysis web app became a world hit and we suddenly have a million requests per minute to analyze sentiments and we experience huge load on sa-webapp and sa-logic. How can we scale the containers?