_________________________________________
/ He who steps on others to reach the top \
\ has good balance. /
-----------------------------------------
\
\
\ __---__
_- /--______
__--( / \ )XXXXXXXXXXX\v.
.-XXX( O O )XXXXXXXXXXXXXXX-
/XXX( U ) XXXXXXX\
/XXXXX( )--_ XXXXXXXXXXX\
/XXXXX/ ( O ) XXXXXX \XXXXX\
XXXXX/ / XXXXXX \__ \XXXXX
XXXXXX__/ XXXXXX \__---->
---___ XXX__/ XXXXXX \__ /
\- --__/ ___/\ XXXXXX / ___--/=
\-\ ___/ XXXXXX '--- XXXXXX
\-\/XXX\ XXXXXX /XXXXX
\XXXXXXXXX \ /XXXXX/
\XXXXXX > _/XXXXX/
\XXXXX--__/ __-- XXXX/
-XXXXXXXX--------------- XXXXXX-
\XXXXXXXXXXXXXXXXXXXXXXXXXX/
""VXXXXXXXXXXXXXXXXXXV""
A simple RESTful api written using Flask with a simple path to production deployment.
See api specification for further details.
You can deploy this application to your Kubernetes cluster by cloning this repo first and using the helm chart provided in /flask-chart
to deploy this simple rest api to your kubernetes cluster. After your app is live, you can access the /health
endpoint to ensure the api is healthy.
-
Install Python
-
Install all required dependencies
pip3 install -r requirements.txt
-
To run your application locally:
python3 hello.py livereload # live reload will save you the hassle of reloading on code changes.
- To run all unit tests:
python3 -m unittest tests/*.py
-
Use the
build.sh
to build the docker image -
Use the
run.sh
to run a local docker container based on the image in step 4. (Optionally use your own)
Note: All test cases should be included in the tests/
folder.
-
Once your testing is complete, push the docker image to your favorite container registry.
-
Edit the container image value in the helm chart and deploy your this application to your kubernetes cluster.
-
Test the helm deployment locally on minikube using:
helm install <release-name> ./flask-chart
You should now see the following pods, services and deployments (Note: the helm release name here is "hello-api")
11:00:58 PM flask-hello-k8s on π master [!?] on π³ v19.03.8
β kubectl get all
NAME READY STATUS RESTARTS AGE
pod/hello-api-flask-chart-7994d796d8-dqcrj 1/1 Running 0 13m
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/hello-api-flask-chart ClusterIP 10.109.170.75 <none> 80/TCP 13m
service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 3h46m
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/hello-api-flask-chart 1/1 1 1 13m
NAME DESIRED CURRENT READY AGE
replicaset.apps/hello-api-flask-chart-7994d796d8 1 1 1 13m
- Use the Helm NOTES.txt as a reference for how to access the API.
NOTES:
1. Get the application URL by running these commands:
echo "$(minikube ip) api.hello.com" | sudo tee -a /etc/hosts
http://api.hello.com/will
http://api.hello.com/ready
http://api.hello.com/health
This sample application is licensed under the MIT License.