This guide walks you through the process of setting up the FireGuard application on your local machine using Minikube and Kubernetes. Follow the steps below to deploy the application and access it through a local service.
Before you start, ensure you have the following prerequisites installed on your machine:
- Docker Deskop - For managing docker images and containers. Install here
- Minikube - For creating a local Kubernetes cluster. Install here
- Kubectl - For interacting with the Kubernetes cluster. Install here
- Postman - For interacting with the API endpoints. Install here
First you need to clone the github repo to you own machine! Go into your working directory in the terminal and paste:
git clone https://github.com/FireGuardProject/Fireguard-Microservices.git
cd Fireguard-Microservices
This repo uses microservices as submodules, so you need to fetch these submodules:
git submodule init
git submodule update
Then you can navigate to the directory containing the Kubernetes configuration files for the FireGuard application:
cd kubernetes
Before starting the process with running minikube, you need to make sure that docker is running. Simply start the Docker Desktop application you downloaded earlier, and make sure that the Docker Engine is running.
Start your Minikube environment with the following command:
minikube start
This command initializes a local Kubernetes cluster using Docker as the driver. It prepares Kubernetes along with necessary addons like the storage-provisioner and the default-storageclass for persistent storage needs.
Once Minikube has started, verify that your kubectl is configured to use the "minikube" cluster and the "default" namespace by default:
kubectl config get-contexts
Deploy the FireGuard application by applying the Kubernetes manifests in the following order:
kubectl apply -f metclient-secret.yaml
kubectl apply -f port-service.yaml
kubectl apply -f logic-service.yaml
kubectl apply -f frcm-deployment.yaml
kubectl apply -f api-deployment.yaml
NB! The previous step will most likely take some time, due to downloading the Docker-image. Wait until the download is completed before moving on to the next step.
Check the status of the deployed resources (pods, services, deployments, etc.) to ensure everything is up and running:
kubectl get all
NB! Run the previous step until it is done, and you have confirmed that everything runs as expected, before moving onto the next step. You need to run kubectl get all each time you want an update of the running state.
Finally, access the FireGuard service through Minikube by running:
minikube service fireguard-service
This command automatically opens the service in your default browser or displays a URL that you can use to access the application.
The url will give empty json shown under:
{
"detail": "Not Found"
}
That's because the url is not correct. The picture below shows where you will find your own IP and port after running the line above.
Use this IP and port (your own, not the one of the picture) when you want to run one of the APIs. We have 5 different APIs you can try out! But first you need a bearer token!
Our API uses token-based authentication. To obtain a token, you must use the /api/token endpoint. We would recommend you to use Postman for this. In Postman send a 'POST' request to the endpoint:
http://<ip>:<port>/api/token
But wait... you need a username and password. For now we will give you access to a test user. Simply use:
- username: test
- password: test
Just to make it easier for youself, you can simply paste the line below into Postman (but remember to change the 'ip' and 'port'!)
curl -d "username=test&password=test" -X POST http://<ip>:<port>/api/token
This call will provide you with a bearer token that can be used for 30 minutes!
FireGuard provides 5 distinct API endpoints for various functionalities.
- Replace 'ip' and 'port' with the IP address and port number provided by Minikube.
- Include the bearer token in the header of your request. In Postman, you can do this by going to the "Authorization" tab, selecting type "Bearer Token", and pasting your token.
- Send a request to the desired endpoint using request type GET, and modify the parameters as you please.
This endpoint calculates fire risk starting from a specific start date.
Parameters:
- start_date (string): The starting date for the calculation (format: YYYY-MM-DD).
- days (int): Number of days after the start date to calculate the risk.
- longitude (float): Longitude of the location.
- latitude (float): Latitude of the location.
Example Request:
http://<ip>:<port>/api/v2/fireriskAfterStartDate/?start_date=2024-03-21&days=4&longitude=5.32415&latitude=60.39299
This endpoint provides the fire risk assessment for a specified number of days prior to the current date.
Parameters:
- days (int): The number of days in the past to assess fire risk.
- longitude (float): Longitude of the location.
- latitude (float): Latitude of the location.
Example Request:
http://<ip>:<port>/api/v2/fireriskPreviousDays/?days=3&longitude=5.32415&latitude=60.39299
This endpoint calculates fire risk for a specific date range.
Parameters:
- start_date (string): The start date of the period (format: YYYY-MM-DD).
- end_date (string): The end date of the period (format: YYYY-MM-DD).
- longitude (float): Longitude of the location.
- latitude (float): Latitude of the location.
Example Request:
http://<ip>:<port>/api/v2/fireriskSpecificPeriod/?start_date=2024-03-20&end_date=2024-03-25&longitude=5.32415&latitude=60.39299
This endpoint predicts the fire risk for a certain number of upcoming days.
Parameters:
- days (int): Number of upcoming days to predict fire risk for.
- longitude (float): Longitude of the location.
- latitude (float): Latitude of the location.
Example Request:
http://<ip>:<port>/api/v2/fireriskUpcomingDays/?days=5&longitude=5.32415&latitude=60.39299
This endpoint assesses the fire risk for the days leading up to a specified end date.
Parameters:
- end_date (string): The end date for the calculation (format: YYYY-MM-DD).
- days (int): Number of days before the end date to calculate the risk.
- longitude (float): Longitude of the location.
- latitude (float): Latitude of the location.
Example Request:
http://<ip>:<port>/api/v2/fireriskBeforeEndDate/?end_date=2024-03-30&days=4&longitude=5.32415&latitude=60.39299
Congratulations, you're the best! You have successfully deployed and accessed the FireGuard application in your local Kubernetes environment using Minikube. This setup is ideal for development and testing purposes. Remember, as you're using the Docker driver on Windows, keep the terminal open to maintain the service tunnel.
minikube stop
๐ Check out this Wiki!
Further, if you want to implement CD pipeline for the repo to the cluster, ArgoCD can be utilized for this task. Here are a guide for implementation. Click here.