{"id":23780899,"url":"https://github.com/ajithvcoder/emlo4-session-13-ajithvcoder","last_synced_at":"2026-04-29T23:01:39.726Z","repository":{"id":269790544,"uuid":"907697261","full_name":"ajithvcoder/emlo4-session-13-ajithvcoder","owner":"ajithvcoder","description":"Fastapi Serve with kubernetes for dog and cat classifier  - The School of AI EMLO-V4 course assignment https://theschoolof.ai/#programs","archived":false,"fork":false,"pushed_at":"2024-12-26T09:07:40.000Z","size":1265,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-08T06:49:32.128Z","etag":null,"topics":["classification","docker","fastapi","kubernetes","machine-learning","minikube"],"latest_commit_sha":null,"homepage":"","language":"Python","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/ajithvcoder.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,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-12-24T07:11:41.000Z","updated_at":"2025-01-16T01:25:33.000Z","dependencies_parsed_at":null,"dependency_job_id":"3e84eb8d-e51a-402d-b212-48a57b4c25c7","html_url":"https://github.com/ajithvcoder/emlo4-session-13-ajithvcoder","commit_stats":null,"previous_names":["ajithvcoder/emlo4-session-13-ajithvcoder"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ajithvcoder/emlo4-session-13-ajithvcoder","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajithvcoder%2Femlo4-session-13-ajithvcoder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajithvcoder%2Femlo4-session-13-ajithvcoder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajithvcoder%2Femlo4-session-13-ajithvcoder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajithvcoder%2Femlo4-session-13-ajithvcoder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ajithvcoder","download_url":"https://codeload.github.com/ajithvcoder/emlo4-session-13-ajithvcoder/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajithvcoder%2Femlo4-session-13-ajithvcoder/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32447312,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-29T22:27:22.272Z","status":"ssl_error","status_checked_at":"2026-04-29T22:10:49.234Z","response_time":110,"last_error":"SSL_read: 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":["classification","docker","fastapi","kubernetes","machine-learning","minikube"],"created_at":"2025-01-01T11:18:13.886Z","updated_at":"2026-04-29T23:01:39.721Z","avatar_url":"https://github.com/ajithvcoder.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"## EMLOV4-Session-13 Assignment - Kubernetes - I: Introduction\n\n### Contents\n\n- [Requirements](#requirements)\n- [Development Method](#development-method)\n    - [Classifier model gen and Fast Api local testing](#classifier-model-gen-and-fast-api-local-testing)\n    - [Instructions to Deployment](#fast-api-service)\n- [Learnings](#learnings)\n- [Results Screenshots](#results-screenshots)\n\n### Requirements\n\n- Create a Minikube Cluster Locally or with a t3a.medium Instance on EC2\n- Deploy the CatDog/Dog Breed Classifier model with FastAPI, use FastHTML for the frontend\n- Your Deployment must have 2 Pods for the Model Service\n- It should have a Service and an Ingress\n- What to Submit\n    - Github Repo with Deployment YAML Files\n    - Instructions to\n        - Start MiniKube\n        - Create the Deployment\n        - Tunnel to the Ingress\n    - Access the FastAPI docs page\n- Output of the following in a .md file in your repository\n    - `kubectl describe \u003cyour_deployment\u003e`\n    - `kubectl describe \u003cyour_pod\u003e`\n    - `kubectl describe \u003cyour_ingress\u003e`\n    - `kubectl top pod`\n    - `kubectl top node`\n    - `kubectl get all -o yaml`\n\n### Classifier model gen and Fast API local testing\n\n- Use [assignment-10](https://github.com/ajithvcoder/emlo4-session-10-ajithvcoder) to generate desried classification model for Cat and dogs\n- Convert torch model to onnx - `python dev/generate_onnx.py`\n- Test onnx model with dog image - `python test_onnx.py`\n- Upload to gdrive and use the id to get it\n- eg: `gdown 1HHS\u003cmodel-id\u003ejSg4tCrNANY --output /workspace/mambaout_model.onnx`\n- Fastapi framework is used for serving at port `8000`\n\n**Docker local testing**\n\n*pre deployment test*\n\n- `docker build -t fastapi-classifier-k8s -f ./Dockerfile . --no-cache`\n\n- `docker run -it  -e PORT=8000 -p 8000:8000  fastapi-classifier-k8s bash`\n\n*Note if you are mounting the folder for debugging then you need to download mambaout_model.onnx again as i am downloading the model only inside docker and reducing the size of repo*\n\n- `docker run -it -v /workspaces/emlo4-session-13-ajithvcoder:/workspace -e PORT=8000 -p 8000:8000  fastapi-classifier-k8s bash`\n\n- `uvicorn app:app --host 0.0.0.0 --port 8000`\n\n### Instructions to Deployment\n\n#### Start MiniKube\n\nSet alias name so that we can give `kubectl` instead of a command like this `minikube kubectl --` and note that you need to set this in each current terminal you are using\n\n- `alias kubectl=\"minikube kubectl --\"`\n\nStart minikube service in ubuntu\n\n- `minikube start`\n\nVerify if minikube is started successfully\n\n- `kubectl get all -n kube-system`\n\n#### Create the Deployment\n\nWe need to push docker image in minikube docker environment to make use of it. So enable minikube docker environment\n\n- `eval $(minikube docker-env)`\n\n- `docker build -t fastapi-classifier-k8s -f ./Dockerfile . --no-cache`\n\n- `eval $(minikube docker-env -u)`\n\nNow enter the directory where .yml files are present and run below command to bring up the pod\n\n- `kubectl apply -f .`\n\nVerify if all are in running status\n\n- `kubectl get pods`\n\nOnce the pods are successfully running forward the pod's port `8000`\n\n- `kubectl port-forward service/classifier-service 8000:80`\n\n#### Tunnel to the Ingress\n\n*Only in your local machine only not in EC2 or codespaces*\n\n- Configure in classifier-ingress.yaml also `host: ajith.fastapi`\n\n- If you are using wsl for ubuntu for windows do below. if you are in linux or windows follow any one of below one\n\n- In **wsl** go to `/etc/hosts`\n\n    ```\n\n    127.0.0.1       ajith.fastapi  localhost\n    ```\n\n- Also if you are using wsl you need to modify in **windows** too\n\n- Open `C:\\Windows\\System32\\drivers\\etc\\hosts` in administrator mode\n\n    ```\n    127.0.0.1       ajith.fastapi  localhost\n    ```\n\n*Tunnel setup*\n\n- minikube service classifier-service\n- minikube tunnel\n- kubectl apply -f .\n\n- `http://ajith.fastapi/` will work now in your local\n\n**Snap minikube start**\n\n![minikube](./assets/snap_minikubestart.png)\n\n**minikube dashboard**\n\n![minikube](./assets/snap_minikube_dashboard.png)\n\n### Learnings\n\n- The systems docker images are different from the kubernetes docker images\nso use `eval $(minikube docker-env)` to get inside kubernetes docker images and build docker images for minikube and then to exit it use `eval $(minikube docker-env -u)`.\n\n- Docker mount will show directories properly only if in both host and inside continer if it matches else it wont work as predicted. eg: without `mamba_out.model` i mounted with  `docker run -it -v /workspaces/emlo4-session-13-ajithvcoder:/workspace -e PORT=8000 -p 8000:8000  fastapi-classifier-k8s bash` command but i was not able to get the `mamba_out.model`  inside container even though i am downloading it inside docker file. So later i identified that the issue is improper docker mount.\n\n### Results\n\n**Access the FastAPI docs page**\n\n![docs](./assets/snap_fastapi_docs.png)\n\n**Serving app screenshot with pod name**\n\nBelow you can see that pod name which is serving is used for prediction also\n\n![pod name](./assets/snap_pod_name.png)\n\n**Prediction screenshot**\n\n![pod name](./assets/snap_prediction.png)\n\n**After refresh**\n\nAfter refresh we can get new pod for a new request in round robin manner\n\n![pod name](./assets/snap_on_referesh.png)\n\n**Report for given commands**\n\n- [reports](./report.md)\n\n\n### Group Members\n\n1. Ajith Kumar V (myself)\n2. Pravin Sagar\n3. Hema M\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fajithvcoder%2Femlo4-session-13-ajithvcoder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fajithvcoder%2Femlo4-session-13-ajithvcoder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fajithvcoder%2Femlo4-session-13-ajithvcoder/lists"}