This is Kubernetes example project of multi-container images running on local Kubernetes Cluster. A topic of the project is orchestrating a fib. number calculator with the use of Kubernetes.
The images used for this project are derived from a previous project that I have done. These images have been pushed to my docker hub profile.
Previous Project Repo: Docker Fib Calculator
My Docker Hub Profile: DockerHub
The following explanation is meant for linux systems
Note: There are two ways in which you can run the application. First way makes use of kubectl and minikube. Any changes made to the app directories such as client, worker or server won't be reflected on the deployed pod versions of the same application. The second way which is an optional setup, allows for you to make changes to the source code. This is allowed by the use of skaffold that tracks the root directories and everything within them.
To run the project locally you will need to:
- Clone the repository
git clone https://github.com/Manojlovic1998/running-multi-container-app-on-k8s
- Make sure you have Docker & Docker Compose installed on your system. If not you can use the following links Docker, Docker Compose to set it up.
- Make sure you have kubernetes, kubectl and minikube installed.
- After you have cloned the repo, go into projects' root directory.
cd running-multi-container-app-on-k8s
- Start your minikube.
minikube start
- Once your minikube is up an running you can apply projects' configuration.
kubectl apply -f k8s
- View the build live from minikube dashboard or run get commands followed by the object type you want to view status of.
minikube dashboard
or
kubectl get <object_type>
- Once everything is up and running you can visit the client application by going to minikubes ip address. To get the address run.
minikube ip
- Type in your browser search bar the ip address.
http://<minikube_ip>/
- Clone the repository
git clone https://github.com/Manojlovic1998/running-multi-container-app-on-k8s
- Make sure you have Docker & Docker Compose installed on your system. If not you can use the following links Docker, Docker Compose to set it up.
- Make sure you have kubernetes, kubectl and minikube installed.
- Make sure you have skaffold installed.
- After you have cloned the repo, go into projects' root directory.
cd running-multi-container-app-on-k8s
- Start your minikube.
minikube start
- Run skaffold command.
skaffold dev
- View the build live from minikube dashboard or run get commands followed by the object type you want to view status of.
minikube dashboard.
- Once everything is up and running you can visit the client application by going to minikubes ip address. To get the address run.
minikube ip
- Type in your browser search bar the ip address.
http://<minikube_ip>/
- Try making changes to client app source code and view the app again in the browser to see if the changes have taken place. In case of a reload bug try reloading the app page.
Client is a frontend Fibonacci index number value calculator application. It is built with the help of React technology. It's main purpose is to facilitate user input action where the data from the input is sent to the server (api). It also is fetching the data from the api on page load with the help of axios library.
The Express server serves as api layer that communicates with Redis and Postgres and passes information to the React app from them.
Express api diagram:
Express Routes Description:
domain/
is a test route that was used to test connection to the app during early development.domain/values/all
queries and sends back all of the data from Postgres db instance. GETdomain/values/current
queries and sends back all of the values from Redis instance. GETdomain/values
receives users submitted data, checks if index is within worker limit to prevent bottleneck, sets a placeholder data in Redis instance, and creates a channel over which it sends the index value that worker picks up to do the calculation. POST
Worker instance listens to Redis instance channel. *Instance channel is established by Express domain/values
route. There the publisher sends index via channel message. Worker picks up the message (index) and uses the following algorithm to find the number at the given index in Fibonacci Sequence.
Simple Algorithm
// Basic solution to fib number
// Takes index and returns its value
function fib(index) {
if (index < 2) return 1;
return fib(index - 1) + fib(index - 2);
}