Skip to content

bitclaw/kubernetes-flask

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Creating a Kubernetes-Ready Microservice Using Flask

We are going to use Docker Compose, but if you want to test your code locally without containers, you can create a virtual environment.

The app we are creating here is an API to read and store quotes in a Mysql database.

pip install virtualenvwrapper
export WORKON_HOME=~/Envs
mkdir -p $WORKON_HOME
source ~/.local/bin/virtualenvwrapper.sh
which python3
mkvirtualenv --python=/usr/bin/python3 learnkubernetes

API Test

To test if our API is responding run:

curl -X Get -i http://0.0.0.0:3000/api/v1/get-quote

To test the POST request and insert a quote to the database, use:

curl -i -H "Content-Type: application/json" -X POST -d '{"quote":"To find a fault is easy; to do better may be difficult. -- Plutarch"}' http://0.0.0.0:3000/api/v1/set-quote

Health check

curl -X Get -i http://0.0.0.0:3000/healthz

Pycharm Troubleshooting

If you get an error regarding about Unresolved reference 'flask_sqlalchemy', delete stubs from the following directory:

grep -R 'sqlalchemy' # this will help you locate the python stub folder in which you will need to delete the stub
cd ~/.PyCharm2019.3/system/python_stubs/618138258

Pycharm Debug

If this doesn't work try removing and adding back the project interpreter, see the below links for more information.

And easier solution was to just set the project interpreter as the Docker one.

Useful Pycharm Links

Useful Python Links

Useful Docker Links

About

Creating a Kubernetes-Ready Microservice

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published