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.
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.
The project consists of the following key components:
-
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.
-
Dockerfile: This file contains instructions to build a Docker image for your Flask application. Docker enables containerization, making your application portable and scalable.
-
Kubernetes Manifests: The
orchestration/
directory contains Kubernetes YAML manifests for deploying and managing your containerized application. Customize these files based on your deployment needs. -
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.
-
Clone Repository: Clone this repository to your local machine using the following command:
git clone https://github.com/ImranAdan/api-docker-k8s-infra-template
-
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.
-
Customize Flask App: Modify the Flask app in the
app/
directory to meet your specific API requirements. -
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.
To run the application locally, follow these steps:
- 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 .
-
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.
Deploying the application to Kubernetes and AWS involves the following steps:
-
Customize Kubernetes manifests in the
orchestration/
directory. -
Update infrastructure
infrastructure/
directory according to your infrastructure requirements. -
Deploy the application using Kubernetes and AWS.
If you would like to contribute to this project, please follow the guidelines in the CONTRIBUTING.md file.
This project is licensed under the MIT License - see the LICENSE file for details.