The goal of the project is to create a local k8s infrastructure and delpoy microservices using Terraform.
Constraints
- Create a monorepo that include infrustructure and microservices
- Manage localstack with one-click
- Save terraform state locally
- Python >= 3.8
- Minikube >= v1.32.0
- Docker >= 25.0.0
- kubectl >= v1.29.0
- Terraform >= 1.7.0
-
The
run.shcommand make it easy to manage the local k8s infrastructure, run these commands in your terminal:echo "api=true" > localstack/localstack.txtchmod +x localstack/run.sh./localstack/run.sh -t plan --create-localstack./localstack/run.sh -t apply(opt --create-localstack only first run) -
Expose cluster
minikube tunnel -
Test (All endpoint)
- MacOS
- Open browser: http://localhost/health
- Linux
- Get IP_MINIKUBE:
minikube ip - Add to /etc/hosts:
IP_MINIKUBE demo.local - Open browser: http://demo.local/health
- Get IP_MINIKUBE:
- MacOS
Once the starting infrastructure run.sh has worked you can start developing your microservices.
Project structure
-
microservices
This is where the microservices of your infrastructure reside. Each folder corresponds to a microservice so you can use any language it is OBLIGATORY to create:
Dockerfileinfrastructurefolder containing the terraform main.tf, the various modules needed, and the env folder with the tfvars. The main file should retrieve the state of the shared infrastructure so that the shared resources can be accessed.
-
infrastructure
The
infrastructurefolder is the basic structure of our cluster. Here you can add all the services and containers common to all microservices. By default, it creates a namespace used. -
localstack
This folder contains files useful for running the entire infrastructure locally. The files contained are:
localstack.txtkey-value file that allows you to indicate which microservices to run locally, so you can run only the services you need locally. Thekeyis the name of the microservice (and its folder withinmicroservices) whilevalueis a true or false, for exampleapi=truerun.shThis script is an entry point that facilitates the startup of the local infrastructuresetup.shinstalls all dependencies for local development
Exec
chmod +x localstack/setup.sh
./localstack/setup.sh
source .activate
pre-commit run --all./localstack/run.sh -t destroyminikube delete
minikube addons enable dashboardminikube dashboard