This is a POC to check if microservices can be made using flask with proper API documentation and openAPI 2.0 support and can be deployed on a kubernetes cluster on local machines using minikube and kubectl .
- Make a python3.x virtual environment using virtualenvwrapper
pip install -r requirements.txt
export FLASK_APP=main.py
flask run
- Build docker image:
docker build -f Dockerfile --rm -t flask_micro_docker:latest .
- Running in interactive mode:
docker run docker run -it -p 8000:5000 flask_micro_docker:latest
- To setup minikube follow official minikube installation guide.
- To setup kubectl follow kubectl installation guide.
kubectl apply -f kubertoy.yaml
- Get the url of your service by using
minikube service flaskr-service --url
- Access swagger ui at http://{base-url}/ui/ in your browser.
- To see the services running and health check use command
minikube dashboard
- Using pytest to run automated tests.
- To run the tests cd into the project root and run
pytest -v
- to run specific test method use
pytest tests/test_hello.py::test_hello -v
- More pytest usage reference.
If you want to run minikube on a Mac, you need to install a virtual machine. The most common VM is VirtualBox. Some recent versions of MacOS don’t allow VirtualBox to be installed (the OS doesn’t recognize Oracle’s Developer ID). Here’s a solution for that (not simple):
Based on these instructions: installation fails for vbox 6.0.8 on osx 10.14.5
- In Terminal, run:
sudo spctl --master-disable
sudo kextcache --clear-staging
- Restart the Mac in Recovery Mode
- Restart, hold down Command-R until the Mac starts up
- In Recovery Mode, go to the Utilities menu and launch the Terminal
- Enter the command:
spctl kext-consent add VB5E2TV963
- Restart the Mac
- Mount the VirtualBox drive image (the .dmg file)
- Run the Uninstall script, to clean up the environment
- Run the VirtualBox installer
- Restore security in Security & Privacy by entering this in a terminal:
sudo spctl --master-enable
Note: this was necessary on one developer's machine, running Mac OS 10.14.6 (Mojave)