Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/shadyosama9/fastapi-kubernetes-deployment-manager
A FastAPI application to manage Kubernetes deployments and fetch Prometheus metrics. This application provides RESTful endpoints to create Kubernetes deployments and retrieve pod details from Prometheus.
https://github.com/shadyosama9/fastapi-kubernetes-deployment-manager
docker fastapi grafana kubernetes prometheus python restful-api
Last synced: 28 days ago
JSON representation
A FastAPI application to manage Kubernetes deployments and fetch Prometheus metrics. This application provides RESTful endpoints to create Kubernetes deployments and retrieve pod details from Prometheus.
- Host: GitHub
- URL: https://github.com/shadyosama9/fastapi-kubernetes-deployment-manager
- Owner: shadyosama9
- Created: 2024-07-14T16:42:25.000Z (4 months ago)
- Default Branch: master
- Last Pushed: 2024-07-14T16:49:42.000Z (4 months ago)
- Last Synced: 2024-10-11T06:04:05.808Z (28 days ago)
- Topics: docker, fastapi, grafana, kubernetes, prometheus, python, restful-api
- Language: Python
- Homepage:
- Size: 3.91 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# FastAPI Kubernetes Deployment Manager
A FastAPI application to manage Kubernetes deployments and fetch Prometheus metrics. This application provides RESTful endpoints to create Kubernetes deployments and retrieve pod details from Prometheus.
## Overview
This project demonstrates how to:
- Use FastAPI to create RESTful endpoints.
- Deploy a FastAPI application on Kubernetes.
- Create Kubernetes deployments programmatically using the Kubernetes Python client.
- Fetch and display metrics from Prometheus.The FastAPI application includes the following endpoints:
- `POST /createdeployment/{deployment_name}`: Create a new Kubernetes deployment with the specified name.
- `GET /getpromdetails`: Fetch and display pod details from Prometheus.## Prerequisites
- **Docker**: To build and run Docker containers.
- **Kubernetes**: A running Kubernetes cluster.
- **kubectl**: Command-line tool for interacting with the Kubernetes cluster.
- **Prometheus**: A running Prometheus instance accessible from the Kubernetes cluster.
- **Python 3.10**: For running the FastAPI application locally.## Steps
1. **Clone the repository**
```bash
git clone https://github.com/yourusername/fastapi-k8s-deployment-manager.git
cd fastapi-k8s-deployment-manager
```2. **Set up environment variables**
- Create a `.env` file in the root of your project with the following content:
```env
PROMETHEUS_URL=http://
```3. **Build the Docker image**
```bash
docker build -t fastapi-k8s-deployment-manager .
```4. **Push the Docker image to Docker Hub (optional)**
```bash
docker tag fastapi-k8s-deployment-manager yourusername/fastapi-k8s-deployment-manager
docker push yourusername/fastapi-k8s-deployment-manager
```5. **Apply Kubernetes configurations**
- Apply RBAC configuration
```bash
kubectl apply -f k8s/rbac.yaml
```- Deploy the FastAPI application
```bash
kubectl apply -f k8s/deployment.yaml
```- Expose the FastAPI application using a service
```bash
kubectl apply -f k8s/service.yaml
```6. **Access the FastAPI application**
- Get the NodePort of the service
```bash
kubectl get svc fast-api-service
```
- Access the application at `http://:`7. **Use the FastAPI application**
- Create a new Kubernetes deployment
```bash
curl -X POST http://:/createdeployment/{deployment_name}
```- Fetch pod details from Prometheus
```bash
curl http://:/getpromdetails
```## Notes
- Ensure your Prometheus instance is running and accessible from the Kubernetes cluster.
- Customize the Kubernetes deployment and service configurations as needed.