Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mxmarchal/k8s-chat
A simple backend service for a chat application, built with Bun.js and PostgreSQL, and deployed on Kubernetes using Minikube. This project is intended for educational purposes only, showcasing backend development, containerization with Docker, and Kubernetes orchestration.
https://github.com/mxmarchal/k8s-chat
bun docker kubernetes minikube postgres typescript
Last synced: about 2 months ago
JSON representation
A simple backend service for a chat application, built with Bun.js and PostgreSQL, and deployed on Kubernetes using Minikube. This project is intended for educational purposes only, showcasing backend development, containerization with Docker, and Kubernetes orchestration.
- Host: GitHub
- URL: https://github.com/mxmarchal/k8s-chat
- Owner: mxmarchal
- Created: 2024-11-19T21:16:35.000Z (about 2 months ago)
- Default Branch: main
- Last Pushed: 2024-11-20T00:09:47.000Z (about 2 months ago)
- Last Synced: 2024-11-20T01:18:51.076Z (about 2 months ago)
- Topics: bun, docker, kubernetes, minikube, postgres, typescript
- Language: TypeScript
- Homepage:
- Size: 6.84 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Chat Backend Service
A simple chat backend service built with Bun.js and PostgreSQL, deployed on Kubernetes. This project is for **educational purposes only** and should never be used in production.
## β οΈ Warning
This project contains hardcoded credentials and lacks proper security measures. It is designed solely for learning purposes to demonstrate:
- Bun.js backend development
- Docker containerization
- Kubernetes deployment
- PostgreSQL integration
- Basic health checks and readiness probes## π§ Prerequisites
- [Bun](https://bun.sh) (v1.1.34 or later)
- [Docker](https://www.docker.com/)
- [Minikube](https://minikube.sigs.k8s.io/)
- [kubectl](https://kubernetes.io/docs/tasks/tools/)## π Local Development
1. Install dependencies:
```sh
cd backend
bun install
```You'll need to have a PostgreSQL database running locally. You can use the following command to start a PostgreSQL container:
```sh
docker run --name postgres -e POSTGRES_PASSWORD=postgres -d -p 5432:5432 postgres
```2. Run the application:
You'll have to create a `.env` file to run the application (see `.env.example`).
```sh
bun start
```3. Test the application:
```sh
curl http://localhost:3000/readyz
``````sh
curl http://localhost:3000/messages
``````sh
curl -X POST http://localhost:3000/messages -H "Content-Type: application/json" -d '{"username": "John", "message": "Hello, world!"}'
```## π³ Docker Containerization
I use a Makefile to build and run the Docker container (see `Makefile`).
Also, it's a docker-compose file to run the container (see `docker-compose.yml`).```sh
make build
make run
```## π Kubernetes Deployment
### Prerequisites
- Minikube installed
- kubectl configured to use Minikube cluster (see [Minikube installation guide](https://minikube.sigs.k8s.io/docs/start/))1. Start Minikube:
```sh
minikube start
```2. Enable the tunnel for LoadBalancer service:
```sh
minikube tunnel
```3. Build the Docker image in Minikubeβs environment:
Minikube uses its own Docker daemon. Configure your terminal to build the image directly inside Minikube's environment.
```sh
make minikube-build
```4. Deploy the application:
```sh
make k8s-up
```5. Access the application:
```sh
minikube service chat-backend-service --url
```Use the provided URL to test the endpoints:
- Retrieve Messages: GET /messages
- Post a Message: POST /message (body: {"username": "Alice", "message": "Hello Minikube!"})6. Stop the application:
```sh
make k8s-down
```## Debugging the k8s cluster
[RTFD](https://kubernetes.io/docs/reference/kubectl/)
But since i'm nice, here's a cheat sheet:
```sh
kubectl get pods
kubectl logs
kubectl describe pod
```