Git Product home page Git Product logo

cd0157-server-deployment-and-containerization's Introduction

Deploying a Flask API

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

In this project you will containerize and deploy a Flask API to a Kubernetes cluster using Docker, AWS EKS, CodePipeline, and CodeBuild.

The Flask app that will be 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 is adequate for local development, but not production, so you will be using 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 involves several steps:

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

For more detail about each of these steps, see the project lesson.

cd0157-server-deployment-and-containerization's People

Contributors

junglebadger avatar kbehrman avatar rcudacity avatar sudkul avatar swwelch avatar tasawar-hussain avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

cd0157-server-deployment-and-containerization's Issues

Load Balancer IP doesn't work

I got as far as trying to test the deployed application (build went through successfully), but I get nothing from the load balance IP address that is given by the command kubectl get services simple-jwt-api -o wide.

What is the next best step to debug this?

Python cfn-response module

When trying to create a stack on AWS using this yml file, I am getting the following error and causes the Stack creation to fail:

Custom Resource failed to stabilize in expected time. If you are using the Python cfn-response module, you may need to update your Lambda function code so that CloudFormation can attach the updated version.

BUILD ERROR ON Deployment to Kubernetes using CodePipeline and CodeBuild

on Create Codebuild and CodePipeline resources using CloudFormation template after inputting everything I got those errors:
User: arn:aws:sts::982818556804:assumed-role/voclabs/user2030857=6276772819 is not authorized to perform: codebuild:CreateProject on resource: arn:aws:codebuild:us-west-2:982818556804:project/jwt-stack with an explicit deny in a service control policy (Service: AWSCodeBuild; Status Code: 400; Error Code: AccessDeniedException; Request ID: 2afc9141-c3d9-4bb5-8818-81e981b6cd77; Proxy: null)
err

DeprecationWarning

When trying to create a stack on AWS CloudFormation using ci-cd-codepipeline.cfn.yml template, I'm getting a deprecation warning.

/var/runtime/botocore/vendored/requests/api.py:72: DeprecationWarning: You are using the put() function from 'botocore.vendored.requests'. This dependency was removed from Botocore and will be removed from Lambda after 2021/01/30. https://aws.amazon.com/blogs/developer/removing-the-vendored-version-of-requests-from-botocore/. Install the requests package, 'import requests' directly, and use the requests.put() function instead.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.