Skip to content

Latest commit

 

History

History
executable file
·
92 lines (72 loc) · 4.23 KB

File metadata and controls

executable file
·
92 lines (72 loc) · 4.23 KB

Deploying a Flask API

This was the project starter repo for the course Server Deployment, Containerization, and Testing.

In this project I containerized and deployed a Flask API to a Kubernetes cluster using Docker, AWS EKS, CodePipeline, and CodeBuild.

The Flask app that was used for this project consists of a simple API with three endpoints:

  • GET '/': This is a simple health check, which returns the response 'Healthy'.
  • POST '/auth': This takes a email and password as json arguments and returns a JWT based on a custom secret.
  • GET '/contents': This requires a valid JWT, and returns the un-encrpyted contents of that token.

The app relies on a secret set as the environment variable JWT_SECRET to produce a JWT. The built-in Flask server was adequate for local development, but not production, so I used the production-ready Gunicorn server when deploying the app.

Prerequisites

#  Mac/Linux/Windows 
python --version

You can download a specific release version from here.

  • Python package manager - PIP 19.x or higher. PIP is already installed in Python 3 >=3.4 downloaded from python.org . However, you can upgrade to a specific version, say 20.2.3, using the command:
#  Mac/Linux/Windows Check the current version
pip --version
# Mac/Linux
pip install --upgrade pip==20.2.3
# Windows
python -m pip install --upgrade pip==20.2.3
  • Terminal
    • Mac/Linux users can use the default terminal.
    • Windows users can use either the GitBash terminal or WSL.
  • Command line utilities:
    • AWS CLI installed and configured using the aws configure command. Another important configuration is the region. Do not use the us-east-1 because the cluster creation may fails mostly in us-east-1. Let's change the default region to:
    aws configure set region us-east-2  
    Ensure to create all your resources in a single region.
    • EKSCTL installed in your system. Follow the instructions available here or here to download and install eksctl utility.
    • The KUBECTL installed in your system. Installation instructions for kubectl can be found here.

Initial setup

  1. Fork the Server and Deployment Containerization Github repo to your Github account.
  2. Locally clone your forked version to begin working on the project.
git clone https://github.com/SudKul/cd0157-Server-Deployment-and-Containerization.git
cd cd0157-Server-Deployment-and-Containerization/
  1. These are the files relevant for the current project:
.
├── Dockerfile 
├── README.md
├── aws-auth-patch.yml #ToDo
├── buildspec.yml      #ToDo
├── ci-cd-codepipeline.cfn.yml #ToDo
├── iam-role-policy.json  #ToDo
├── main.py
├── requirements.txt
├── simple_jwt_api.yml
├── test_main.py  #ToDo
└── trust.json     #ToDo 

Project Steps

Completing the project involved several steps:

  1. Writing a Dockerfile for a simple Flask API
  2. Building and testing the container locally
  3. Creating an EKS cluster
  4. Storing a secret using AWS Parameter Store
  5. Creating a CodePipeline pipeline triggered by GitHub checkins
  6. Creating a CodeBuild stage which will build, test, and deploy your code

Author

Joy Wanjiru

I am a data science enthusiast and a software engineering graduate from ALX and I love working with Python especially because of it's vast pool of libraries for scientific computing