From aa17c7a2dce14388d1efe399eb9864d81d192031 Mon Sep 17 00:00:00 2001 From: Aleksandr Tcitlionok <803797+terghalin@users.noreply.github.com> Date: Thu, 5 Dec 2024 03:06:01 +0000 Subject: [PATCH] update(app): add examples and README file --- .dockerignore | 1 + README.md | 93 +++++++++++++++++++++++++++++++++++- examples/k8s/deployment.yaml | 39 +++++++++++++++ examples/k8s/rbac.yaml | 29 +++++++++++ 4 files changed, 160 insertions(+), 2 deletions(-) create mode 100644 examples/k8s/deployment.yaml create mode 100644 examples/k8s/rbac.yaml diff --git a/.dockerignore b/.dockerignore index 49482b1..92c7425 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1 +1,2 @@ app/resources.db +.env diff --git a/README.md b/README.md index 6fe6cff..697d927 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,92 @@ -# Metal Check +# MetalCheck Backend -Metal Check - Get tips and information about your Kubernetes and on-premise servers. +MetalCheck is a backend service that provides real-time insights into virtual machines, physical nodes, and Kubernetes clusters. +It supports deployment in an EKS environment and offers features like data aggregation, export, and pseudographics visualization. + +--- + +## Features +- **Metal Nodes**: Track hardware details like CPU, memory, and storage for physical nodes. +- **Virtual Machines**: Monitor VMs from cloud providers like Hetzner. +- **Kubernetes Clusters**: Query Kubernetes clusters to gather node and namespace data. +- **Data Export**: Export collected data in JSON or YAML format. +- **Pseudographics**: Terminal-based data visualization (optional). + +--- + +## Project Structure + +## Project Structure + +```plaintext +metal-check-backend/ +├── app/ +│ ├── __init__.py # Initialization +│ ├── main.py # FastAPI entry point +│ ├── database.py # SQLite DB setup and operations +│ ├── extras/ +│ │ ├── pseudographics.py # CLI visualization tools +│ ├── routes/ +│ │ ├── __init__.py # Initialization for routes +│ │ ├── metal.py # Routes for metal nodes +│ │ ├── vm.py # Routes for virtual machines +│ │ ├── k8s.py # Routes for Kubernetes clusters +│ │ ├── export.py # Data export routes +│ ├── example/k8s/ +│ │ ├── rbac.yaml # RBAC configuration for Kubernetes +│ │ ├── deployment.yaml # Deployment configuration 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 :latest +docker push :latest +``` + +### Deploy to EKS + +Apply RBAC and deployment configurations: + +```bash +kubectl apply -f app/example/k8s/rbac.yaml +kubectl apply -f app/example/k8s/deployment.yaml +``` + +### Access the Service + +Retrieve the LoadBalancer IP: + +```bash +kubectl get svc -n metalcheck +``` + +Test the API: + +```bash +curl http:///k8s/data +``` + +## 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 | +| POST | /vm/data | Add a new virtual machine | +| GET | /k8s/data | Get Kubernetes cluster information | +| GET | /export | Export data in JSON or YAML format | diff --git a/examples/k8s/deployment.yaml b/examples/k8s/deployment.yaml new file mode 100644 index 0000000..2ffd502 --- /dev/null +++ b/examples/k8s/deployment.yaml @@ -0,0 +1,39 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: metalcheck-backend + labels: + app: metalcheck +spec: + replicas: 1 + selector: + matchLabels: + app: metalcheck + template: + metadata: + labels: + app: metalcheck + spec: + containers: + - name: backend + image: :latest + ports: + - containerPort: 8000 + env: + - name: KUBERNETES_SERVICE_HOST + value: "kubernetes.default" + - name: KUBERNETES_SERVICE_PORT + value: "443" +--- +apiVersion: v1 +kind: Service +metadata: + name: metalcheck-backend +spec: + selector: + app: metalcheck + ports: + - protocol: TCP + port: 80 + targetPort: 8000 + type: LoadBalancer diff --git a/examples/k8s/rbac.yaml b/examples/k8s/rbac.yaml new file mode 100644 index 0000000..ec41847 --- /dev/null +++ b/examples/k8s/rbac.yaml @@ -0,0 +1,29 @@ +apiVersion: v1 +kind: ServiceAccount +metadata: + name: metalcheck-sa + namespace: metalcheck +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: Role +metadata: + namespace: metalcheck + name: metalcheck-role +rules: +- apiGroups: [""] + resources: ["pods", "nodes", "namespaces"] + verbs: ["get", "list", "watch"] +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + name: metalcheck-rolebinding + namespace: metalcheck +subjects: +- kind: ServiceAccount + name: metalcheck-sa + namespace: metalcheck +roleRef: + kind: Role + name: metalcheck-role + apiGroup: rbac.authorization.k8s.io