Skip to content

desainis/flask-hello-k8s

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

forthebadge made-with-python technical-debut didnt-ask


 _________________________________________
/ 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""

Flask Hello World in K8s

A simple RESTful api written using Flask with a simple path to production deployment.

API Specifications

See api specification for further details.

Steps

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.

Deploying to Kubernetes cluster

Native application development

  1. Install Python

  2. Install all required dependencies pip3 install -r requirements.txt

  3. To run your application locally:

python3 hello.py livereload # live reload will save you the hassle of reloading on code changes.
  1. To run all unit tests:
python3 -m unittest tests/*.py
  1. Use the build.sh to build the docker image

  2. 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.

  1. Once your testing is complete, push the docker image to your favorite container registry.

  2. Edit the container image value in the helm chart and deploy your this application to your kubernetes cluster.

  3. 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
  1. 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

License

This sample application is licensed under the MIT License.

MIT License