{"id":20289938,"url":"https://github.com/thoughtscript/python_pyramid_kub_2024","last_synced_at":"2026-04-07T16:31:17.235Z","repository":{"id":262530557,"uuid":"882493569","full_name":"Thoughtscript/python_pyramid_kub_2024","owner":"Thoughtscript","description":"Experiments with Python, Kubernetes, and Pyramid","archived":false,"fork":false,"pushed_at":"2024-12-29T23:16:29.000Z","size":41,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-04T04:42:01.899Z","etag":null,"topics":["docker-compose","kubernetes","postgres","pyramid","python"],"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/Thoughtscript.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}},"created_at":"2024-11-02T23:21:04.000Z","updated_at":"2024-12-29T23:16:33.000Z","dependencies_parsed_at":"2024-11-12T23:28:59.410Z","dependency_job_id":"726f478e-439b-441e-a3fe-aa46fd0eaa7c","html_url":"https://github.com/Thoughtscript/python_pyramid_kub_2024","commit_stats":null,"previous_names":["thoughtscript/python_pyramid_kub_2024"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Thoughtscript%2Fpython_pyramid_kub_2024","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Thoughtscript%2Fpython_pyramid_kub_2024/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Thoughtscript%2Fpython_pyramid_kub_2024/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Thoughtscript%2Fpython_pyramid_kub_2024/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Thoughtscript","download_url":"https://codeload.github.com/Thoughtscript/python_pyramid_kub_2024/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241787487,"owners_count":20020099,"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":["docker-compose","kubernetes","postgres","pyramid","python"],"created_at":"2024-11-14T15:05:35.218Z","updated_at":"2025-12-31T01:03:19.052Z","avatar_url":"https://github.com/Thoughtscript.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# python_pyramid_kub_2024\r\n\r\n[![](https://img.shields.io/badge/Python-3.13-yellow.svg)](https://www.python.org/downloads/) \r\n[![](https://img.shields.io/badge/Pyramid-2.0-red.svg)](https://trypyramid.com/) \r\n[![](https://img.shields.io/badge/Docker-blue.svg)](https://www.docker.com/) \r\n[![](https://img.shields.io/badge/Kubernetes-purple.svg)](https://kubernetes.io/) \r\n[![](https://img.shields.io/badge/Postgres-16.2-lightblue.svg)](https://hub.docker.com/_/postgres)\r\n\r\nVery simple exploration of Python + Pyramid.\r\n\r\n## TODO Check List\r\n\r\n- [x] Basic Pyramid App\r\n- [x] Basic Pyramid APIs\r\n- [x] Pyramid + Postgres\r\n- [x] Docker-Compose and equivalents in Kubernetes\r\n  - [X] Kubernetes build pipeline suitable for local builds and `minikube`\r\n  - [X] Address this [ancient question](https://stackoverflow.com/questions/74598540/how-to-mount-a-sql-file-in-a-init-container-in-order-to-bootstrap-postgres-datab)\r\n- [x] Add Tests\r\n  - [x] Add Better Integration Tests (that fully inject a view)\r\n- [x] Learn more about Kubernetes in 2024 (`deployments`, `services`, `configMaps`, `volumes`, `volume-claims`, etc.)\r\n- [x] Learn how to initialize Postgres with a script correctly (presumably through `containerInit`)\r\n  - [x] I created a `configMap`, mounted, and executed a command in `deployment \u003c containers`.\r\n  - [x] Tested dropping the SQL script into `docker-entrypoint-initdb.d`.\r\n- [x] Learn about ways to generate fixed hostnames and/or URLs (for `minikube` since it has some issues with this)\r\n   - [x] `NodePorts`\r\n   - [x] [Ingress](https://minikube.sigs.k8s.io/docs/handbook/addons/ingress-dns/#Windows)\r\n- [x] Basic SSL\r\n  - [x] Looks like `uvicorn`, TLS/SSl, and `asgiref` are presently incompatible: https://github.com/encode/uvicorn/issues/1118\r\n  - [x] In Production, one would presumably deploy a Proxy w/ SSL out in front (still bad practice to not SSL encrypt everything - internal network sniffing)\r\n  - [x] So is Waitress: https://github.com/Pylons/waitress/issues/287\r\n\r\n## Setup and Use\r\n\r\n1. For **Docker Compose**: \r\n   * Execute `bash run-dc.sh`\r\n2. For Kubernetes:\r\n   * Execute `bash run-k.sh`\r\n   * Will generate and display a dynamic **IP Address**.\r\n     * You may need to update the **Postman Collection Variables** accordingly to test.\r\n     * This is apparently required for `minikube` [local testing](https://kubernetes.io/docs/tasks/access-application-cluster/create-external-load-balancer/).\r\n     * Seems to be the case that either the local **IP Address** or **Port Numbers** must be [manually generated or looked up](https://minikube.sigs.k8s.io/docs/handbook/accessing/) (in `minikube` [alone](https://medium.com/globant/load-balance-microservices-using-kubernetes-minikube-88b78dae4796) at some step regardless of whether one uses `nodePort`, a `minikube` **Load Balancer**, or `minikube service python-pyramid --url`).\r\n       * `nodePort` requires mapping from `8000` to `30000`-`32767`.\r\n       * Even with `nodePort` set in the [config](./kubernetes/python-deployment.yaml) the **IP Address** (**Host**) will be randomly generated and must still be manually exposed.\r\n\r\nNote that **Pyramid** API Requests may not appear in the browser as rendered text (w/out a satisfactory Renderer). \r\n   * Check the Developer Console for the correct Response.\r\n   * Postman is supplied to simplify basic testing.\r\n\r\n## Helpful Commands\r\n\r\n`bash`:\r\n\r\n```bash\r\n# Remove every Docker image, dangling volume, minikube, etc. and startover\r\n## use only if you know what you're doing!\r\nbash restart.sh \r\n\r\n# Make SSl certs for local testing\r\n# cd python \u0026\u0026 bash ssl.sh\r\n```\r\n\r\n`docker`:\r\n\r\n```bash\r\n# Display running Docker Containers\r\ndocker stats ## verify that the Docker builds are contained within the Kubernetes environment\r\n```\r\n\r\n`kubectl`:\r\n\r\n```bash\r\nkubectl get services\r\nkubectl get pods\r\nkubectl describe services/python-pyramid-postgres\r\n```\r\n\r\n`minikube`:\r\n\r\n```bash\r\nminikube dashboard # Display minikube pods and namespaces\r\n## can find the Pod and Exec into the Container easily throug the supplied interface\r\n```\r\n\r\n\u003e Check out [run-k.sh](./run-k.sh) for other relevant Kubernetes commands!\r\n\r\n`pytest`\r\n\r\n```bash\r\n# Within the Python container\r\ncd tests \u0026\u0026 pytest functional_tests.py\r\ncd tests \u0026\u0026 pytest *.py \r\n## Note that \"Deprecated call to `pkg_resources.declare_namespace('zope')\" is a known Python-wide issue\r\n```\r\n\r\n## Views\r\n\r\n**Serving File Content Dynamically**\r\n\r\n\u003e Using the resolve DNS hostname from `docker-compose`:\r\n\r\n1. Simple HTML View: http://localhost:8000/index.html\r\n   * https://docs.pylonsproject.org/projects/pyramid_cookbook/en/latest/static_assets/serving-files.html\r\n2. Direct Static File Serve: http://localhost:8000/static/test.html\r\n\r\n## Resources and Links\r\n\r\n1. https://kubernetes.io/docs/reference/kubernetes-api/service-resources/service-v1/\r\n2. https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/pod-v1/\r\n3. https://kubernetes.io/docs/tutorials/services/connect-applications-service/\r\n4. https://kubernetes.io/docs/tasks/configure-pod-container/translate-compose-kubernetes/\r\n5. https://github.com/Pylons/pyramid/blob/main/docs/quick_tutorial/static_assets/tutorial/home.pt\r\n6. https://docs.pylonsproject.org/projects/pyramid_cookbook/en/latest/static_assets/serving-files.html\r\n7. https://github.com/testdrivenio/flask-vue-kubernetes/tree/master\r\n8. https://www.digitalocean.com/community/tutorials/how-to-deploy-postgres-to-kubernetes-cluster","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthoughtscript%2Fpython_pyramid_kub_2024","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthoughtscript%2Fpython_pyramid_kub_2024","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthoughtscript%2Fpython_pyramid_kub_2024/lists"}