Giter Club home page Giter Club logo

api-docker-k8s-infra-template's Introduction

Basic Containerized Application Template

Overview

This repository serves as a starting point for building containerized applications using Python Flask for the API, Kubernetes for container orchestration, and AWS CDK for infrastructure deployment.

Contents

Introduction

This project provides a simple yet powerful template for containerized applications. It leverages the following technologies:

  • GitHub: As the version control system and repository store.
  • Python Flask: A lightweight and extensible web framework for building API applications.
  • Kubernetes (K8s): An open-source container orchestration platform for automating deployment, scaling, and management of containerized applications.
  • AWS CDK (Cloud Development Kit): An open-source software development framework to define cloud infrastructure in code and provision it through AWS CloudFormation.

Components

The project consists of the following key components:

  1. Flask App: The Python Flask application serves as the API for your containerized application. Customize it to fit your specific requirements by adding endpoints and business logic. This is expanded with a MongoDB backend for data storage.

  2. Dockerfile: This file contains instructions to build a Docker image for your Flask application. Docker enables containerization, making your application portable and scalable.

  3. Kubernetes Manifests: The orchestration/ directory contains Kubernetes YAML manifests for deploying and managing your containerized application. Customize these files based on your deployment needs.

  4. AWS CDK or Terraform: The infrastructure/ directory includes AWS CDK code written in Python; or Terraform. This code defines the infrastructure required to deploy your containerized application on AWS.

Setup

  1. Clone Repository: Clone this repository to your local machine using the following command:

    git clone https://github.com/ImranAdan/api-docker-k8s-infra-template
  2. Install Dependencies: Ensure you have Python, Docker, Kubernetes, and AWS CDK or Terraform installed on your local machine. Each project contains README files to get this started.

  3. Customize Flask App: Modify the Flask app in the app/ directory to meet your specific API requirements.

  4. Deploy Flask App to the Cloud: The final aspect would be to deploy to a given cloud provider, in this instance it is AWS. The specific method depends on the approach chosen.

Usage

To run the application locally, follow these steps:

  1. Build the Docker image:

This project has been built on an M2 machine and therefore you will need to specify the default platform to support ARM chips.

docker image build --platform linux/amd64 --tag api-docker-k8s-infra-template .
  1. Run the Docker container:

    docker container run -d -p 8080:8080 api-docker-k8s-infra-template

Visit http://localhost:8080 in your browser to access the Flask app.

Deployment

Deploying the application to Kubernetes and AWS involves the following steps:

  1. Customize Kubernetes manifests in the orchestration/ directory.

  2. Update infrastructure infrastructure/ directory according to your infrastructure requirements.

  3. Deploy the application using Kubernetes and AWS.

Contributing

If you would like to contribute to this project, please follow the guidelines in the CONTRIBUTING.md file.

License

This project is licensed under the MIT License - see the LICENSE file for details.

api-docker-k8s-infra-template's People

Contributors

imranadan avatar

Stargazers

Urban Teacher avatar

Watchers

 avatar Urban Teacher avatar

api-docker-k8s-infra-template's Issues

Configure and Deploy EKS Cluster

  • Configure your AWS EKS cluster by creating a kubeconfig file to enable communication with the cluster from your local machine.
  • Deploy the EKS cluster using the Terraform scripts you created in the previous step.

Test Base Docker Image

Test the base docker image to ensure it works locally as expected before deploying to Kubernetes cluster.

Setup a Github Repo

Setup a Github repository for a sample containerised and orchestrated api.

Activating working environments for Python CDK

It is not easy to onboard Python developers into their local working environments (again) especially when they have set up an AWS accounts. When choosing CDK, which is AWS's preferred IAC solution then this is the problem we will see again.

This can be a problem, however, we have two options here:

  • More discovery on Python and Pip (Pip is the dependency management solution for Python)
  • Use Typescript which is fully supported (Learning Language barrier, JS and static typing a requirement)
  • Use Terraform and skip all AWS specfifc nuances (Learn Hcl)

We need to decide what the best option is given our skills and learning potential.

Set up AWS EKS Cluster

  • Set up an AWS account if you don't have one.
  • Install and configure the AWS CLI on your local machine.
  • Install and configure kubectl, the command-line tool for interacting with Kubernetes clusters.

Use Terraform to define and provision the necessary AWS resources for an EKS cluster (VPC, subnets, EKS cluster, etc.). You can organize your Terraform code in a directory structure for better maintainability.

Deploy Application on EKS

  • Create Kubernetes deployment and service YAML files for your containerized application.
  • Deploy your application on the EKS cluster using kubectl.
  • Verify that your application is running correctly on the EKS cluster.

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.