A key-value storage server built with FastAPI, etcd, and Kubernetes.
- Python
- FastAPI
- Docker version v20.10.23
- minikube v1.30.1
Create .env file outside app folder. The env should contain field ETCD_HOST, ETCD_PORT.
Screenshot of env file
-
Local Installation
- In one terminal run command
etcd
- In another terminal run following commands and set ETCD_HOST=localhost, ETCD_PORT=2379 in .env file
source venv.sh deactivate source venv/bin/activate export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python uvicorn app.main:app --reload --reload-dir app --port 8000
-
Installation with Docker Compose
- In order to run the app on docker container configure the .env file with below host and port values
ETCD_HOST=etcd ETCD_PORT=2379
- Run the below command to create app and etcd containers
docker-compose up
- Visit the localhost:8000/docs to access the API.
-
Kubernetes Deployments, services and Installation
- Run below command to start minikube, minikube dashboard and metrics-server
minikube start minikube addons enable metrics-server minikube dashboard
- Run the below command to generate secrets for fastapi application pods. The ETCD_HOST and ETCD_PORT values should not be changed. It should same as below command.
kubectl create secret generic etcd-secret --from-literal=ETCD_HOST=etcd --from-literal=ETCD_PORT=2379 --dry-run -o yaml > secrets.yaml
- Run the below commands to create deployment, service, HorizontalPodAutoScaler and volumes.
kubectl apply -f=master-backend.yaml -f=master-etcd.yaml kubectl apply -f=secrets.yaml
- Expose the service on local machine
minikube service backend