This repository contains the complete guide for setting up, building, and deploying the Marketplace project in local environments using Docker Compose and Kubernetes (Minikube).
Before getting started, make sure the following tools are installed:
- Docker Desktop
- Minikube
- Kubectl
Start by cloning the repository to your local machine:
git clone https://github.com/RobisonTorres/MarketplaceDockerKubernetes.git
cd MarketplaceThe docker-compose.yml file located in the root directory is configured to create all necessary containers for running the project locally. This includes:
- Database
- Backend
- Frontend
docker compose up --buildThis command:
- Builds the images if they do not already exist
- Pulls required base images if necessary
- Starts all defined services
The frontend uses an Nginx image and is exposed on port 8081, according to the Docker Compose configuration.
Open your browser and access:
http://localhost:8081Start the Minikube cluster:
minikube startThis command:
- Creates a virtual machine
- Initializes a local Kubernetes cluster
- Configures the kubectl context automatically
The project uses the YAML files located in the k8s/ directory to apply Kubernetes resources such as:
- Namespace
- Deployments
- Services
- ConfigMaps
- Secrets
Connect local Docker to Minikube:
& minikube -p minikube docker-env --shell powershell | iexBuild the backend image:
docker build -t marketplace:1.0.0 ./backendBuild the frontend image:
docker build -t marketplace-frontend:1.0.0 ./frontend1 - Apply the namespace:
kubectl apply -f k8s/namespace.yaml2 - Apply database:
kubectl apply -f k8s/mysql/3 - Apply backend:
kubectl apply -f k8s/backend/4 - Apply frontend:
kubectl apply -f k8s/frontend/The backend's deployment is configured to wait for the database to be ready before starting, ensuring proper initialization.
To open the frontend service in your browser:
minikube service nginx -n marketplaceThis command will automatically open the application URL.
To test Horizontal Pod Autoscaler (HPA) behavior, create a temporary load generator pod:
kubectl run load-generator -n marketplace --rm -it --image=busybox -- /bin/shInside the container, execute:
while true; do wget -q -O- http://marketplace:8080/actuator/health; doneThis continuously sends requests to the backend service, generating CPU load.
In a separate terminal, monitor scaling activity:
kubectl get hpa -n marketplace -wThis command watches the HPA metrics in real time and displays scaling events as they occur.
The application should now be fully operational in both Docker Compose and Kubernetes environments.
The project includes a GitHub Actions workflow defined in .github/workflows/ci-cd.yml that automates the build and deployment process in Github actions. This workflow is triggered on pushes to the main branch and performs all the tests and deployment steps automatically.