This project can be deployed locally or in a containerized workflow depending on the user's preference. Instructions for both deployments are located in the installation section.
-
Users will be familiar with the process to deploy a local kubernetes cluster and how to deploy resources on cluster
-
All requests to api will be recorded in audit log (including request to get audit log)
This project requires the software below as a prerequisite. It has been split into two sections depending on the type of deployment
Containerized deployment
-
docker desktop (required only if deploying k8s cluster using kind)
choco install docker-desktop (windows through chocolatey) brew install docker (mac os through homebrew)
-
kubernetes cli (kubectl)
choco install kubernetes-cli (windows through chocolatey) brew install kubernetes-cli (mac os thorugh homebrew)
-
helm (optional)
choco install kubernetes-helm (windows through chocolatey) brew install helm (mac os through homebrew)
-
kubernetes cluster (local)
-
kind (requires docker desktop)
choco install kind (windows through chocolatey) brew install kind (mac os though chocolatey)
or
- minikube
choco install minikube (windows through chocolatey) brew install minikube (mac os through homebrew)
Local Deployment
-
Python3
choco install python (windows through chocolatey) brew install [email protected] (macos through homebrew)
-
FastAPI (requires python)
pip install fastapi
-
Uvicorn (requires python)
pip install "uvicorn[standard]"
- Clone or Download the code from the repository
git clone https://github.com/khan-belal/jumble-word-api.git
or
Pull image from docker hub
docker pull belalkhan/jumble-word-api:latest
-
Make required changes to Docker file/application file
-
Build docker image
docker build -t khan-belal/jumble-word-api .
- Run new built image
docker run -p 80:80 khan-belal/jumble-word-api
Containerized deployment
- Clone or Download the code from the repository
git clone https://github.com/khan-belal/jumble-word-api.git
-
Deploy a local kubernetes cluster.
If using kind use the included config file to ensure networking ports are exposed for connectivity
kind create cluster --name my-cluster --config=kind-config.yaml
If using minikube, start the kubernetes cluster.
minkube start
-
Check status of cluster and confirm kubectl has been setup correctly
kubectl get nodes
-
Create namespace for application
kubectl create namespace jumble-word
-
Deploy the application
If using helm
helm install --namespace jumble-word jumble-word-api --values ./jumble-word-api/values.yaml
Otherwise, kubectl can be used to deploy the app directly
kubectl apply -f -namespace jumble-word api-deployment.yaml
Local Deployment
-
Ensure python is installed
python3 --version
-
Install required packages for FastAPI/Uvicorn
pip install fastapi
pip install "uvicorn[standard]"
- Start the uvicorn server
uvicorn main:app
The api enables 2 functionalities with usage examples for each function below:
jumble-word The main function of the api is to jumble words that are supplied to the api.
To request a jumbled word from the api, first locate the ip address of the pod/instance running the api.
If running on the local machine, the address for the api will be
If running on a local kubernetes cluster, obtain the ip address of the running node. This is especially important if running the cluster in WSL2 on Windows.
minikube ip
If using kind obtain the ip address of the linux instance running in WSL2 (windows only)
ifconfig eth0
Once the ip address of the api is located, the api can be queried using the examples below:
Jumble-word To scramble the word happy, send the request to the api using:
localhost:8000/jumble-word?word=happy
Output:
ppayh
Audit api To get an audit log of the last 10 calls made to the api, run:
localhost:8000/audit
Output:
"{\"api_call\": \"Get audit-log\", \"query\": \"N/A\", \"payload\": \"N/A\"}\n"