All checks were successful
CI Pipeline / Build and Push Docker Image (push) Successful in 3m53s
150 lines
4.1 KiB
Markdown
150 lines
4.1 KiB
Markdown
# MetalCheck Backend
|
|
|
|
MetalCheck is a backend service that provides insights into virtual machines, physical nodes, and Kubernetes clusters.
|
|
It supports deployment in an EKS environment and offers features like data aggregation, import from APIs, and data export.
|
|
|
|
---
|
|
|
|
## Features
|
|
|
|
- **Metal Nodes**: Track hardware details like CPU, memory, and storage for physical nodes. Import node data from JSON files.
|
|
- **Virtual Machines**: Track virtual machine details like CPU, memory, and storage. Import VM data from Hetzner Cloud API or JSON files.
|
|
- **Kubernetes Clusters**: Query Kubernetes clusters to gather node and namespace data.
|
|
- **Data Export**: Export collected data in JSON or YAML format for further processing or visualization.
|
|
|
|
---
|
|
|
|
## Project Structure
|
|
|
|
```plaintext
|
|
metalcheck-backend/
|
|
├── app/
|
|
│ ├── __init__.py # Initialization
|
|
│ ├── main.py # FastAPI entry point
|
|
│ ├── database.py # SQLite DB setup and operations
|
|
│ ├── routes/
|
|
│ │ ├── __init__.py # Initialization for routes
|
|
│ │ ├── metal.py # Routes for metal nodes
|
|
│ │ ├── vm.py # Routes for virtual machines
|
|
│ │ ├── k8s.py # Routes for Kubernetes clusters
|
|
│ │ ├── think.py # Routes for AI summary
|
|
│ │ ├── export.py # Data export routes
|
|
│ ├── examples/k8s/
|
|
│ │ ├── rbac.yaml # RBAC configuration for Kubernetes
|
|
│ │ ├── deployment.yaml # Deployment configuration for EKS
|
|
│ │ ├── configmap.yaml # ConfigMap for EKS
|
|
├── Dockerfile # Docker container configuration
|
|
├── requirements.txt # Python dependencies
|
|
├── .dockerignore # Files to ignore during image build
|
|
└── README.md # Project documentation
|
|
```
|
|
|
|
# Setup and Deployment
|
|
## Prerequisites
|
|
- Python 3.10+
|
|
- Docker and kubectl installed
|
|
- Access to an EKS cluster
|
|
- AWS CLI configured with appropriate permissions
|
|
|
|
## Build and Deploy
|
|
### Build and Push Docker Image
|
|
|
|
```bash
|
|
docker build -t metalcheck-backend .
|
|
docker tag metalcheck-backend:latest <your-ecr-repo>:latest
|
|
docker push <your-ecr-repo>:latest
|
|
```
|
|
|
|
### Deploy to EKS
|
|
|
|
Modify and apply RBAC and deployment configurations:
|
|
|
|
```bash
|
|
kubectl apply -f examples/k8s/rbac.yaml
|
|
kubectl apply -f examples/k8s/configmap.yaml
|
|
kubectl apply -f examples/k8s/deployment.yaml
|
|
```
|
|
|
|
### Access the Service
|
|
|
|
Retrieve the LoadBalancer IP:
|
|
|
|
```bash
|
|
kubectl get svc -n metalcheck
|
|
```
|
|
|
|
Test the API:
|
|
|
|
```bash
|
|
curl http://<EXTERNAL-IP>/k8s/data
|
|
```
|
|
|
|
## Kubernetes Integration
|
|
|
|
The `/k8s/data` endpoint retrieves information about:
|
|
|
|
- Nodes: CPU, memory, and allocatable pods.
|
|
- Namespaces: List of all namespaces in the cluster.
|
|
|
|
## Endpoints
|
|
|
|
| Method | Endpoint | Description |
|
|
| --- | --- | --- |
|
|
| GET | /metal/data | Get all physical node data |
|
|
| POST | /metal/data | Add a new physical node |
|
|
| GET | /vm/data | Get all virtual machine data |
|
|
| GET | /vm/import_hetzner | Import VM data from Hetzner API |
|
|
| POST | /vm/data | Add a new virtual machine |
|
|
| GET | /k8s/data | Get Kubernetes cluster information |
|
|
| GET | /think/k8s | Get AI summary for Kubernetes cluster |
|
|
| GET | /export | Export data in JSON or YAML format |
|
|
|
|
## Hetzner Integration
|
|
To fetch virtual machines from Hetzner Cloud:
|
|
|
|
1. Ensure your Hetzner API token is available as an environment variable:
|
|
|
|
```shell
|
|
export HETZNER_TOKEN=<your-token>
|
|
```
|
|
|
|
2. Use the /vm/import-hetzner endpoint:
|
|
|
|
```shell
|
|
curl http://<EXTERNAL-IP>/vm/import_hetzner
|
|
```
|
|
|
|
## Data Export
|
|
|
|
1. Export in YAML format:
|
|
|
|
```shell
|
|
curl -X GET "http://<EXTERNAL-IP>/export?format=yaml"
|
|
```
|
|
|
|
2. Export in JSON format:
|
|
|
|
```shell
|
|
curl -X GET "http://<EXTERNAL-IP>/export?format=json"
|
|
```
|
|
|
|
## MetalCheck Helm Chart
|
|
|
|
This Helm chart deploys the MetalCheck backend on a Kubernetes cluster.
|
|
|
|
### Installation
|
|
|
|
#### Prerequisites
|
|
|
|
- Kubernetes cluster (1.18+ recommended)
|
|
- Helm 3.x installed
|
|
- Docker image for MetalCheck backend
|
|
|
|
#### Install Chart
|
|
|
|
1. Update `values.yaml` with your specific configurations.
|
|
2. Install the chart:
|
|
|
|
```bash
|
|
helm install metalcheck ./metalcheck-helm
|