This project demonstrates how to set up a complete infrastructure using Minikube to run a Node.js application with MySQL, monitoring using Prometheus and Grafana, and logging with Fluent Bit and Loki.
- Minikube installed
- Docker installed
- kubectl installed
- Helm installed
Begin by starting Minikube. This creates a single-node Kubernetes cluster locally.
minikube start
To run the app locally, use Docker Compose to spin up the Node.js app and MySQL database:
docker-compose up --build
Ensure the app runs successfully in Docker before proceeding to Kubernetes.
Minikube uses its own Docker environment, so you need to load the images into it:
eval $(minikube docker-env)
docker build -t docker-node-crud-mysql-app .
docker build -t postgres:13.2 .
Once the images are available in Minikube, deploy them using Kubernetes Deployment
and Service
YAML files:
kubectl apply -f app1-deployment.yaml
kubectl apply -f postgres-deployment.yaml
Follow the Prometheus documentation to initialize it in your cluster. Use the Docker command line to configure it:
kubectl apply -f prometheus.yaml
To load Fluent Bit configurations into your cluster:
kubectl apply -f fluent-bit-config.yaml
This will set up log forwarding from your app to Loki or another storage backend.
Use Helm to install Loki and Grafana for log collection and visualization:
helm repo add grafana https://grafana.github.io/helm-charts
helm install loki grafana/loki-stack --set grafana.enabled=true,prometheus.enabled=true
Finally, ensure your Node.js app is running in the Minikube cluster and accessible. You can check the status of the pods:
kubectl get pods
Access the app via Minikube's NodePort or service.
- Prometheus: Used for gathering application and system metrics.
- Grafana: For visualizing metrics and logs from the system.
- Fluent Bit: For collecting and shipping logs to Loki.
- Loki: Log aggregation platform, paired with Grafana for log analysis.
- Ensure images are correctly built and loaded into Minikube.
- Verify that the
kubectl get pods
shows running pods. - Check Prometheus and Fluent Bit logs for any setup issues.
- For Grafana, check port-forwarding if the UI doesn't open.
- Automate the deployment process using CI/CD pipelines.
- Add more monitoring and alerting mechanisms.
This README provides clear instructions for setting up the cluster and all components, helping any user to reproduce your environment.