{"id":22495224,"url":"https://github.com/osbm/ain3003-term-project","last_synced_at":"2026-04-08T21:31:29.811Z","repository":{"id":216580634,"uuid":"737332675","full_name":"osbm/ain3003-term-project","owner":"osbm","description":"Kubernetes mongodb flask showcase project","archived":false,"fork":false,"pushed_at":"2024-01-10T01:05:42.000Z","size":130,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-27T21:16:03.954Z","etag":null,"topics":["docker","flask","kubernetes","mongodb"],"latest_commit_sha":null,"homepage":"","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/osbm.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2023-12-30T16:46:36.000Z","updated_at":"2024-01-10T22:52:06.000Z","dependencies_parsed_at":"2024-01-11T01:08:54.336Z","dependency_job_id":"759842f9-3c22-4a4f-9206-fe02808dd49d","html_url":"https://github.com/osbm/ain3003-term-project","commit_stats":null,"previous_names":["osbm/ain3003-term-project"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/osbm/ain3003-term-project","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/osbm%2Fain3003-term-project","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/osbm%2Fain3003-term-project/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/osbm%2Fain3003-term-project/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/osbm%2Fain3003-term-project/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/osbm","download_url":"https://codeload.github.com/osbm/ain3003-term-project/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/osbm%2Fain3003-term-project/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31575421,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-08T14:31:17.711Z","status":"ssl_error","status_checked_at":"2026-04-08T14:31:17.202Z","response_time":54,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["docker","flask","kubernetes","mongodb"],"created_at":"2024-12-06T19:26:27.147Z","updated_at":"2026-04-08T21:31:29.796Z","avatar_url":"https://github.com/osbm.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"I have chosen Project Proposal 1 from [project-proposals.md](project-proposals.md).\n\n![project-screenshot](./assets/screenshot.png)\n\n## Using MongoDB on Kubernetes to Build and Launch a Containerized Python Application with Flask\n\n### Objective\n\nThe purpose of this assignment is to develop a Python application that is scalable and containerized, capable of interacting with a MongoDB database, Flask, and to install it on a Kubernetes cluster.\n\nStudents will gain important experience working with database interactions, Kubernetes orchestration, and containerization in a real-world setting with this project. It goes over the basic ideas behind setting up and running containerized apps in a distributed setting.\n\nYou can find more information regarding the proposal [here](project-proposals.md).\n\n# Steps to run the project\n\nFirst of all you need a kubernetes cluster. I have used minikube for this project. I also installed mongo client on my machine to test stuff and feed the test data to the mongo instance.\n\n## Step 1: Setup the kubernetes cluster\n\nLets start the minikube cluster\n\n```\nminikube start\n```\n\nAfter this lets look at the status of the cluster\n\n```\nkubectl get nodes\n```\n\nOutput should be something like this\n\n```\nNAME       STATUS   ROLES           AGE   VERSION\nminikube   Ready    control-plane   22s   v1.28.3\n```\n\n## Step 2: Create the mongo statefulset\n\nNow lets create the mongo statefulset. This will create a mongo instance with 1 replica. We want 2 things from this mongo database 1 feed the data to the python app and 2 to expose the mongo instance to outside of the kubernetes cluster. So we will create a service that uses the mongo statefulset as its backend.\n\n```\nkubectl apply -f mongo-statefulset.yaml\n```\n\nLets check the status of the kubernetes:\n\n```\nkubectl get all\n```\n\nOutput should be something like this:\n\n```\nNAME            READY   STATUS              RESTARTS   AGE\npod/mongodb-0   0/1     ContainerCreating   0          4s\n\nNAME                 TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE\nservice/kubernetes   ClusterIP   10.96.0.1    \u003cnone\u003e        443/TCP   3m30s\n\nNAME                       READY   AGE\nstatefulset.apps/mongodb   0/1     4s\n```\n\nLets wait until the mongodb-0 pod is ready.\n\n```\nNAME            READY   STATUS    RESTARTS   AGE\npod/mongodb-0   1/1     Running   0          2m4s\n\nNAME                 TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE\nservice/kubernetes   ClusterIP   10.96.0.1    \u003cnone\u003e        443/TCP   5m30s\n\nNAME                       READY   AGE\nstatefulset.apps/mongodb   1/1     2m4s\n```\n\nThats better.\n\n## Step 3: Create the mongo service\n\nNow lets create the service for the mongo statefulset. This will expose the mongo instance to outside of the kubernetes cluster.\n\n```\nkubectl apply -f mongo-service.yaml\n```\n\nLets check the status of the kubernetes (from now on I will not show the output of this command):\n\n```\nNAME            READY   STATUS    RESTARTS   AGE\npod/mongodb-0   1/1     Running   0          3m24s\n\nNAME                 TYPE           CLUSTER-IP      EXTERNAL-IP   PORT(S)           AGE\nservice/kubernetes   ClusterIP      10.96.0.1       \u003cnone\u003e        443/TCP           6m50s\nservice/mongodb      LoadBalancer   10.98.168.165   \u003cpending\u003e     27017:31692/TCP   2s\n\nNAME                       READY   AGE\nstatefulset.apps/mongodb   1/1     3m24s\n```\n\n## Step 4: Import the data to the mongo instance\n\nNow lets import the data to the mongo instance. For this we need to get the mongo uri. We can get it by running the following command:\n\n```\nexport MONGO_URI=mongodb://$(minikube service mongodb --url | sed 's,.*/,,')\nmongoimport --file=bookstore.json --collection=bookstorecollection --uri=$MONGO_URI --jsonArray --db=bookstoredatabase\n```\n\n## Step 4.1 (optional): Check the data in the mongo instance\n\nYou can actually access the mongo instance from your machine by running the following command:\n\n```\nmongosh $MONOGO_URI\n```\n\nAnd once inside:\n\n```\nshow dbs\n```\n\nOutput should be something like this:\n\n```\nadmin              32.00 KiB\nbookstoredatabase  32.00 KiB\nconfig             12.00 KiB\nlocal              32.00 KiB\n```\n\n## Step 5: Create the flask deployment\n\nNow lets create the flask deployment. This will create a flask instance with 1 replica. The docker image of the flask application will be pulled from [my docker hub repository](https://hub.docker.com/r/osbm/ain3003-flask-application). The docker image is created from the Dockerfile in the flask-application directory. So this will take some time to pull the image.\n\n```\nkubectl apply -f flask-deployment.yaml\n```\n\nLets check the status of the kubernetes:\n\n```\nNAME                             READY   STATUS    RESTARTS   AGE\npod/flask-app-76966bdd64-gmxmx   1/1     Running   0          39s\npod/mongodb-0                    1/1     Running   0          14m\n\nNAME                 TYPE           CLUSTER-IP      EXTERNAL-IP   PORT(S)           AGE\nservice/kubernetes   ClusterIP      10.96.0.1       \u003cnone\u003e        443/TCP           17m\nservice/mongodb      LoadBalancer   10.98.168.165   \u003cpending\u003e     27017:31692/TCP   10m\n\nNAME                        READY   UP-TO-DATE   AVAILABLE   AGE\ndeployment.apps/flask-app   1/1     1            1           40s\n\nNAME                                   DESIRED   CURRENT   READY   AGE\nreplicaset.apps/flask-app-76966bdd64   1         1         1       39s\n\nNAME                       READY   AGE\nstatefulset.apps/mongodb   1/1     14m\n```\n\n\n## Step 6: Create the flask service\n\nNow lets create the flask service. This will expose the flask instance to outside of the kubernetes cluster.\n\n```\nkubectl apply -f flask-service.yaml\n```\n\nLets check the status of the kubernetes:\n\n```\nNAME                             READY   STATUS    RESTARTS   AGE\npod/flask-app-76966bdd64-gmxmx   1/1     Running   0          3m47s\npod/mongodb-0                    1/1     Running   0          17m\n\nNAME                 TYPE           CLUSTER-IP      EXTERNAL-IP   PORT(S)           AGE\nservice/flask        LoadBalancer   10.109.40.227   \u003cpending\u003e     5000:30669/TCP    6s\nservice/kubernetes   ClusterIP      10.96.0.1       \u003cnone\u003e        443/TCP           20m\nservice/mongodb      LoadBalancer   10.98.168.165   \u003cpending\u003e     27017:31692/TCP   14m\n\nNAME                        READY   UP-TO-DATE   AVAILABLE   AGE\ndeployment.apps/flask-app   1/1     1            1           3m48s\n\nNAME                                   DESIRED   CURRENT   READY   AGE\nreplicaset.apps/flask-app-76966bdd64   1         1         1       3m47s\n\nNAME                       READY   AGE\nstatefulset.apps/mongodb   1/1     17m\n```\n\n\n## Step 7: Test the flask application\n\nNow lets enjoy the flask application.\n\n```\nminikube service flask\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fosbm%2Fain3003-term-project","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fosbm%2Fain3003-term-project","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fosbm%2Fain3003-term-project/lists"}