{"id":16507827,"url":"https://github.com/noahgift/kubernetes-hello-world-python-flask","last_synced_at":"2025-04-06T09:11:26.629Z","repository":{"id":141812257,"uuid":"348366151","full_name":"noahgift/kubernetes-hello-world-python-flask","owner":"noahgift","description":"A Kubernetes Hello World Project","archived":false,"fork":false,"pushed_at":"2025-01-10T23:01:00.000Z","size":16,"stargazers_count":35,"open_issues_count":4,"forks_count":86,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-03-30T08:12:08.185Z","etag":null,"topics":["coursera","docker-container","flask","kubernetes","mlops","oreilly","practicalmlops","python-flask"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"cc0-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/noahgift.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":"2021-03-16T13:52:31.000Z","updated_at":"2025-01-27T07:24:04.000Z","dependencies_parsed_at":null,"dependency_job_id":"8dfbf0bd-fa7d-4621-ab8d-be8c2a2ca7ab","html_url":"https://github.com/noahgift/kubernetes-hello-world-python-flask","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noahgift%2Fkubernetes-hello-world-python-flask","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noahgift%2Fkubernetes-hello-world-python-flask/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noahgift%2Fkubernetes-hello-world-python-flask/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noahgift%2Fkubernetes-hello-world-python-flask/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/noahgift","download_url":"https://codeload.github.com/noahgift/kubernetes-hello-world-python-flask/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247457803,"owners_count":20941906,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["coursera","docker-container","flask","kubernetes","mlops","oreilly","practicalmlops","python-flask"],"created_at":"2024-10-11T15:30:54.012Z","updated_at":"2025-04-06T09:11:26.592Z","avatar_url":"https://github.com/noahgift.png","language":"Python","readme":"## 🎓 Pragmatic AI Labs | Join 1M+ ML Engineers\n\n### 🔥 Hot Course Offers:\n* 🤖 [Master GenAI Engineering](https://ds500.paiml.com/learn/course/0bbb5/) - Build Production AI Systems\n* 🦀 [Learn Professional Rust](https://ds500.paiml.com/learn/course/g6u1k/) - Industry-Grade Development\n* 📊 [AWS AI \u0026 Analytics](https://ds500.paiml.com/learn/course/31si1/) - Scale Your ML in Cloud\n* ⚡ [Production GenAI on AWS](https://ds500.paiml.com/learn/course/ehks1/) - Deploy at Enterprise Scale\n* 🛠️ [Rust DevOps Mastery](https://ds500.paiml.com/learn/course/ex8eu/) - Automate Everything\n\n### 🚀 Level Up Your Career:\n* 💼 [Production ML Program](https://paiml.com) - Complete MLOps \u0026 Cloud Mastery\n* 🎯 [Start Learning Now](https://ds500.paiml.com) - Fast-Track Your ML Career\n* 🏢 Trusted by Fortune 500 Teams\n\nLearn end-to-end ML engineering from industry veterans at [PAIML.COM](https://paiml.com)\n\n# Kubernetes Hello World\nA Kubernetes Hello World Project for Python Flask.  This project uses [a simple Flask app that returns correct change](https://github.com/noahgift/flask-change-microservice) as the base project and converts it to Kubernetes.\n![kubernetes-load-balanced-cluster](https://user-images.githubusercontent.com/58792/111511557-3f45a280-8725-11eb-8e4a-5f5ef787796d.png)\n\nThis recipe is in the book Practical MLOps.\n\n![9781098103002](https://user-images.githubusercontent.com/58792/111000927-eb1b7680-8350-11eb-8e24-d41064590fc1.jpeg)\n\n\n## Assets in Repo\n\n* `Makefile`:  [Builds project](https://github.com/noahgift/kubernetes-hello-world-python-flask/blob/main/Makefile)\n* `Dockerfile`:  [Container configuration](https://github.com/noahgift/kubernetes-hello-world-python-flask/blob/main/Dockerfile)\n* `app.py`:  [Flask app](https://github.com/noahgift/kubernetes-hello-world-python-flask/blob/main/app.py)\n* `kube-hello-change.yaml`: [Kubernetes YAML Config](https://github.com/noahgift/kubernetes-hello-world-python-flask/blob/main/kube-hello-change.yaml)\n\n## Get Started\n\n* Create Python virtual environment `python3 -m venv ~/.kube-hello \u0026\u0026 source ~/.kube-hello/bin/activate`\n* Run `make all` to install python libraries, lint project, including `Dockerfile` and run tests\n\n## Build and Run Docker Container\n\n* Install [Docker Desktop](https://www.docker.com/products/docker-desktop)\n\n* To build the image locally do the following.\n\n`docker build -t flask-change:latest .` or run `make build` which has the same command.\n\n* To verify container run `docker image ls`\n\n* To run do the following:  `docker run -p 8080:8080 flask-change` or run `make run` which has the same command\n\n* In a separate terminal invoke the web service via curl, or run `make invoke` which has the same command \n\n`curl http://127.0.0.1:8080/change/1/34`\n\n```bash\n[\n  {\n    \"5\": \"quarters\"\n  }, \n  {\n    \"1\": \"nickels\"\n  }, \n  {\n    \"4\": \"pennies\"\n  }\n]\n```\n\n* Stop the running docker container by using `control-c` command\n\n## Running Kubernetes Locally\n\n* Verify Kubernetes is working via docker-desktop context\n\n```bash\n(.kube-hello) ➜  kubernetes-hello-world-python-flask git:(main) kubectl get nodes\nNAME             STATUS   ROLES    AGE   VERSION\ndocker-desktop   Ready    master   30d   v1.19.3\n```\n\n* Run the application in Kubernetes using the following command which tells Kubernetes to setup the load balanced service and run it:  \n\n`kubectl apply -f kube-hello-change.yaml` or run `make run-kube` which has the same command\n\nYou can see from the config file that a load-balancer along with three nodes is the configured application.\n\n```yaml\napiVersion: v1\nkind: Service\nmetadata:\n  name: hello-flask-change-service\nspec:\n  selector:\n    app: hello-python\n  ports:\n  - protocol: \"TCP\"\n    port: 8080\n    targetPort: 8080\n  type: LoadBalancer\n\n---\napiVersion: apps/v1\nkind: Deployment\nmetadata:\n  name: hello-python\nspec:\n  selector:\n    matchLabels:\n      app: hello-python\n  replicas: 3\n  template:\n    metadata:\n      labels:\n        app: hello-python\n    spec:\n      containers:\n      - name: flask-change\n        image: flask-change:latest\n        imagePullPolicy: Never\n        ports:\n        - containerPort: 8080\n```\n\n* Verify the container is running\n\n`kubectl get pods`\n\nHere is the output:\n\n```bash\nNAME                            READY   STATUS    RESTARTS   AGE\nflask-change-7b7d7f467b-26htf   1/1     Running   0          8s\nflask-change-7b7d7f467b-fh6df   1/1     Running   0          7s\nflask-change-7b7d7f467b-fpsxr   1/1     Running   0          6s\n```\n\n* Describe the load balanced service:\n\n`kubectl describe services hello-python-service`\n\nYou should see output similar to this:\n\n```bash\nName:                     hello-python-service\nNamespace:                default\nLabels:                   \u003cnone\u003e\nAnnotations:              \u003cnone\u003e\nSelector:                 app=hello-python\nType:                     LoadBalancer\nIP Families:              \u003cnone\u003e\nIP:                       10.101.140.123\nIPs:                      \u003cnone\u003e\nLoadBalancer Ingress:     localhost\nPort:                     \u003cunset\u003e  8080/TCP\nTargetPort:               8080/TCP\nNodePort:                 \u003cunset\u003e  30301/TCP\nEndpoints:                10.1.0.27:8080,10.1.0.28:8080,10.1.0.29:8080\nSession Affinity:         None\nExternal Traffic Policy:  Cluster\nEvents:                   \u003cnone\u003e\n```\n\nInvoke the endpoint to curl it:  \n\n`make invoke`\n\n```bash\ncurl http://127.0.0.1:8080/change/1/34\n[\n  {\n    \"5\": \"quarters\"\n  }, \n  {\n    \"1\": \"nickels\"\n  }, \n  {\n    \"4\": \"pennies\"\n  }\n]\n```\n\nTo cleanup the deployment do the following: `kubectl delete deployment hello-python`\n\n## References\n\n* Azure [Kubernetes deployment strategy](https://azure.microsoft.com/en-us/overview/kubernetes-deployment-strategy/)\n* Service [Cluster Config](https://kubernetes.io/docs/tasks/access-application-cluster/service-access-application-cluster/) YAML file\n* [Kubernetes.io Hello World](https://kubernetes.io/blog/2019/07/23/get-started-with-kubernetes-using-python/)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnoahgift%2Fkubernetes-hello-world-python-flask","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnoahgift%2Fkubernetes-hello-world-python-flask","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnoahgift%2Fkubernetes-hello-world-python-flask/lists"}