this is a fully featured/functional application involving routing, authentication, database, migrations, testing, docker and k8s deployment.
For those who like to see the bigger picture, this is for you.
- Built with ExpressJs and Typescript
- Validation with Zod
- Authetication with JWT and Passport
- Database integration and migrations with Prisma
- Testing with Vitest
- Containerized app with Docker
- Deployment using minikube and k8s
make sure you have Nodejs and Yarn installed on your machine.
To install the Dependencies :
$ yarn install
Now to bootstrap the application :
$ yarn dev
And the application will be running on port 3000
First, build the image :
$ docker build . -t express-k8s
Second, run the container :
$ docker run -d -p 3000:3000 --name express-k8s-container express-k8s
Or to run with docker-compose
:
$ docker compose up app -d
Make sure you first run app either normally or withing docker.
To run the tests, just run:
$ yarn test:dev # watch mode
$ yarn test:ci # run and exit
Make sure you have minikube and k8s installed.
First, build the image with docker.
Second, load the image in minikube:
$ minikube image load express-k8s
Now we can create the configMap, Secret, Service, Ingress and Deployment:
$ kubectl apply -f ./k8s/app-configMap.yaml
$ kubectl apply -f ./k8s/app-secret.yaml
$ kubectl apply -f ./k8s/app-deployment.yaml # will create deploy and svc
To start receiving connections, there are 2 approaches we can follow:
we can utilize kubectl port-forward
feature to access the service like so :
$ kubectl port-forward service/express-k8s 3000:3000
Or we could utilize minikube tunneling :
minikube service express-k8s
First make sure to enable minikube addons for ingress:
$ minikube addon enable ingress
$ minikube addon enable ingress-dns
Second, create the ingress object:
$ kubectl apply -f ./k8s/app-ingress.yaml
Now, our ingress doesn't actually have an external ip that we can go to, so we need minikube to help us in this matter.
Utilizing the tunnel
feature of minikube :
$ minikube tunnel
Minikube now offers 127.0.0.1
as an external ip address for the ingress, but there is one step left, we need to add a port mapping for our host expressk8s.com
in your hosts
file.
You will find this file located under /etc/hosts
on MacOs, or under C:\Windows\System32\drivers\etc\hosts
on Windows.
Just append this line to the end of the file :
127.0.0.1 expressk8s.com
Now you can go to expressk8s.com/health-check
and you will see that the application is healthy ๐
This project is meant to be community driven mainly, so if you have any suggestions for features, fixes or improvements feal free to file an issue explaining the old behavior and the desired behavior.
You can first file a feature request in the issues sections to discuss the feature you want to add, and then you can create a pull request for it.
Please make sure you write unit tests for the code you write and make sure all the tests are passing.