{"id":15878759,"url":"https://github.com/darkwizard242/k8s-app-demo","last_synced_at":"2026-02-02T21:08:31.571Z","repository":{"id":104869662,"uuid":"592887593","full_name":"darkwizard242/k8s-app-demo","owner":"darkwizard242","description":"FastAPI app, PostgreSQL db and Helm chart to deploy to Kubernetes Cluster","archived":false,"fork":false,"pushed_at":"2024-09-21T03:09:16.000Z","size":47,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-07-04T17:50:04.224Z","etag":null,"topics":["fastapi","helm","helm-charts","kubernetes","minikube","postgresql"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/darkwizard242.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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}},"created_at":"2023-01-24T18:47:08.000Z","updated_at":"2023-02-19T19:40:39.000Z","dependencies_parsed_at":"2023-11-11T05:29:29.002Z","dependency_job_id":"9f5183a1-b427-436e-9c99-a4c99f7a24a8","html_url":"https://github.com/darkwizard242/k8s-app-demo","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/darkwizard242/k8s-app-demo","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darkwizard242%2Fk8s-app-demo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darkwizard242%2Fk8s-app-demo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darkwizard242%2Fk8s-app-demo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darkwizard242%2Fk8s-app-demo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/darkwizard242","download_url":"https://codeload.github.com/darkwizard242/k8s-app-demo/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darkwizard242%2Fk8s-app-demo/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29019682,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-02T18:51:31.335Z","status":"ssl_error","status_checked_at":"2026-02-02T18:49:20.777Z","response_time":58,"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":["fastapi","helm","helm-charts","kubernetes","minikube","postgresql"],"created_at":"2024-10-06T02:41:43.881Z","updated_at":"2026-02-02T21:08:31.538Z","avatar_url":"https://github.com/darkwizard242.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# k8s-app-demo\n\nThis repository contains a sample container app (utilizes **FastAPI** framework), let's call it \"**tooling**\", that connects to a PostgreSQL database. Repository also contains a Helm Chart to release it to Kubernetes Cluster for demo/learning purposes.\n\nTo get familiar with some of the Kubernetes objects, please [read this](/INFO.md).\n\n## Requirements:\n\nThe following applications are utilized in this project, and thus, are required:\n\n- [minikube](https://minikube.sigs.k8s.io/docs/start/)\n- [kubectl](https://kubernetes.io/docs/tasks/tools/#kubectl)\n- [helm](https://helm.sh/docs/intro/install/)\n- [docker](https://docs.docker.com/get-docker/)\n- [docker-compose](https://docs.docker.com/compose/install/)\n\n## Cloning Repository:\n\n#### Using HTTPS protocol:\n```shell\ngit clone https://github.com/darkwizard242/k8s-app-demo.git k8s-app-demo\n```\n\n#### Using SSH protocol:\n```shell\ngit clone git@github.com:darkwizard242/k8s-app-demo.git k8s-app-demo\n```\n\n## Tutorial (docker/docker-compose)\n\nThis project already contains a `Dockerfile` and `docker-compose`. Using these, you can run the FastAPI app and Postgresql database.\n\n### 1. Build container image:\n\nRun the following to build the container image:\n```shell\ndocker-compose build\n```\n\n### 2. Run container image:\n\nRun the following to provision the container(s) in a detached mode (if you prefer non-detached mode, execute `docker-compose up`):\n```shell\ndocker-compose up -d\n```\n\n\n## Tutorial (Kubernetes/minikube)\n\n### 1. Getting **Minikube** ready:\n\nFollowing command starts a local kubernetes cluster with Kubernetes version `1.25.3` while utilizing `docker` as the driver.\n```shell\nminikube start --driver=docker --kubernetes-version=1.25.3\n```  \n\nValidate the output of Cluster.\n\n```shell\nkubectl cluster-info\n```\n\nRetrieve Nodes information:\n\n```shell\nkubectl get nodes -o wide\n```\n\nValidate all pods in `kube-system` namespace are **READY**:\n```shell\nkubectl -n kube-system get pods\n```\n\n### 2. Install **metrics-server**:\n\nApply YAML manifest for `metrics-server`:\n```shell\nkubectl apply -f metrics-server.yaml\n```\n\nEnsure `metrics-server` Pod is in **READY** state:\n```shell\nkubectl get pods -l k8s-app=metrics-server -n kube-system\n```\n\nIf POD is in a state where image PULL has failed, attempt to PULL using the following:\n```shell\nminikube ssh docker pull k8s.gcr.io/metrics-server/metrics-server:v0.6.2\n```\n\n### 3. Utilize minikube's docker daemon and build image:\n\nTo build and run container (in this case _docker_ images) in minikube's environment, execute the following to configure the appropriate environment variables:\n\n```shell\neval $(minikube docker-env)\n```\n\nBuild the container image:\n```shell\ndocker build -t local/tooling:v1 .\n```\n\n### 4. Deploy and validate:\n\nFor the purpose of this tutorial, we will release the helm chart against a specific namespace called `demo'. Let's get started by creating the namespace:\n```shell\nkubectl create ns demo\n```\n\nPull dependent chart to disk:\n```shell\nhelm dependency build helmchart/\n```\n\nDeploy the Kubernetes Objects defined in the _Helm Chart_ using **helm** to  the previously created `demo` namespace while naming the Helm Release as **tooling**:\n```shell\nhelm upgrade -i tooling helmchart/ --namespace demo\n```\n\nOnce deployed, validate that all Pods are `demo` namespace are in READY state. _**NOTE** that it may take a few minutes for the Pods to be in READY state as a postgresql image is pulled down and rolled out, and is required for the app to successfully initialize_).\n```shell\nkubectl get pods -n demo\n```\n\nHelm chart test hooks are part of the chart, run the following to let helm perform those tests for you:\n```shell\nhelm test tooling -n demo\n```\n\nTo tail the app logs, run the following:\n```shell\nkubectl logs -f -l app.kubernetes.io/name=tooling -n demo\n```\n\n\n### 5. Access Application Endpoints:\n\nBy default, `ClusterIP` is used in this helm chart, which technically means that the `Service` endpoint is only accessible within the cluster. \n\nIn order to access the application endpoints, `kubectl port-forward` can be used. It will allow connection/traffic to a local port to be forwarded to the port of the `Service` in the cluster for navigation/access purposes.\n\nThe command below will setup port forwarding (`\u003cHOST_PORT_80\u003e:\u003cSVC_PORT_80\u003e`) on a local host port **80** to be forwarded to the `Service` port, which also is running on port **80**.\n\n```shell\nkubectl port-forward svc/tooling 80:80 -n demo\n```\n\nPlease note that `kubectl port-forward` process runs interactively (i.e. as a foreground process | use `CTRL+C` or `CMD+C` keys to end the process), so you may need to open another terminal session for any other activities.\n\n\nThe following command intializes a Pod that makes calls to the `Service` Endpoint with the hostname path to retrieve hostname of the Pods traffic is routed to:\n```shell\nkubectl run -n demo -i --tty load-generator --rm --image=busybox --restart=Never -- sh -c \"while sleep 0.01; do wget -q -O- http://tooling.demo.svc.cluster.local/private/hostname \u0026\u0026 echo; done\"\n```\n\n### 6. Load testing (optional):\n\nFollowing command will run a pod based on Apache Bench that will load test the **Service** Endpoint:\n```shell\nkubectl run -i --tty apache-bench --rm --image=jordi/ab --restart=Never -- -k -c 100 -t 300s http://tooling.demo.svc.cluster.local/private/hostname\n```\n\nIn the mean time, you can monitor the HorizontalPodAutoscaler to view scale-in and scale-out activities:\n```shell\nkubectl get hpa tooling -n demo -w\n```\n\n### 7. Cleanup:\n\nUninstall the helm chart:\n```shell\nhelm uninstall tooling -n demo\n```\n\nStop minikube cluster:\n```shell\nminikube stop\n```\n\nDelete minikube cluster:\n```shell\nminikube delete\n```\n\n\n## Endpoint Requests (optional)\n\n##### GET Request (`/`):\n\n```shell\ncurl -i -H \"Content-Type: text/html\" -X GET http://localhost/\n```\n\n##### GET Request (`/private/hostname`):\n\n```shell\ncurl -i -H \"Content-Type: application/json\" -X GET http://localhost/private/hostname\n```\n\n##### GET Request (`/health/liveness`):\n\n```shell\ncurl -i -H \"Content-Type: application/json\" -X GET http://localhost/health/liveness\n```\n\n##### GET Request (`/health/readiness`):\n\n```shell\ncurl -i -H \"Content-Type: application/json\" -X GET http://localhost/health/readiness\n```\n\n##### GET Request (`/secrets`):\n\n```shell\ncurl -i -H \"Content-Type: application/json\" -X GET http://localhost/secrets\n```\n\n##### POST Request (`/publisher`):\n\n```shell\ncurl -i -d '{\"text\":\"HTTP POST method testing\"}' -H \"Content-Type: application/json\" -X POST http://localhost/publisher\n```\n\n## License\n\n[MIT](/LICENSE)\n\n## Author Information\n\nThis project was developed by [Ali Muhammad](https://www.alimuhammad.dev/).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdarkwizard242%2Fk8s-app-demo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdarkwizard242%2Fk8s-app-demo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdarkwizard242%2Fk8s-app-demo/lists"}