Skip to content

This repository contains deploying my Python ( Hello World ) App in Kubernetes Cluster. For this project I chose AWS as my CSP and its EKS service to launch a K8s cluster.

Notifications You must be signed in to change notification settings

ShivangShandilya/Python-App-in-K8s-Cluster

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python-App-in-K8s-Cluster

About the Project

Creating a hello world API with Python using FastAPI, bundle it up as a container image, and then deploy it to a Kubernetes cluster on Amazon Web Services (AWS)!

Built With

Why use FastAPI??

FastAPI is a modern, fast (high-performance), web framework for building APIs with Python 3.7+ based on standard Python type hints.

The key features are:

  • Fast: Very high performance, on par with NodeJS and Go (thanks to Starlette and Pydantic). One of the fastest Python frameworks available.

  • Fast to code: Increase the speed to develop features by about 200% to 300%. *

  • Fewer bugs: Reduce about 40% of human (developer) induced errors. *

  • Intuitive: Great editor support. Completion everywhere. Less time debugging.

  • Easy: Designed to be easy to use and learn. Less time reading docs.

  • Short: Minimize code duplication. Multiple features from each parameter declaration. Fewer bugs.

Getting Started

  • First we create a virtual environment
python3 -m venv ./venv

The module used to create and manage virtual environments is called venv. venv will usually install the most recent version of Python that you have available. If you have multiple versions of Python on your system, you can select a specific Python version by running python3 or whichever version you want.

  • Installing packages
pip install fastapi
pip install uvicorn

FastAPI is the framework you’ll use to build your API, and Uvicorn is the server that will use the API you build to serve requests.

  • Make a basic FastAPI file

If you don't know how to make one, just copy the one from repository and just like that, you have a fully functional API application with some best practices like automatic documentation and serialization built in.

This code defines your application, but it won’t run on itself if you call it with python directly. To run it, you need a server program. In the steps above, you already installed Uvicorn. That will be your server.

  • Create and build a simple Dockerfile
docker build -t {your preferred name} .
  • Create a repository at DockerHub and push your image there

  • Log in to your AWS account and via its EKS service, create a Kubernetes Cluster

  • Create a simple demployment and service file for the cluster and appply them using following command:

kubectl apply -f .
  • Now to deploy your application on cluster
kubectl port-forward {any running pod name} 8080:80

Usage

The primary goal of this project is to help you learn how to deploy an application on Kubernetes cluster via a CSP

About

This repository contains deploying my Python ( Hello World ) App in Kubernetes Cluster. For this project I chose AWS as my CSP and its EKS service to launch a K8s cluster.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published