Giter Club home page Giter Club logo

python-fastapi-azure-k8s-cluster's Introduction

Python FastAPI Azure K8S Cluster

fastapi-0.103.2-informational Build Status

This project demonstrates deploying a FastAPI application onto an Azure Kubernetes Cluster. Azure Pipelines have been created to build and push the service docker image to an Azure Container Registry. And also deploy the service to a Kubernetes cluster. Azure resources created have been written in Terraform can be found in Azure DevOps repository here 1.

Note

This repository was original created within Azure DevOps and is now being mirrored to this GitHub repository. Source of truth will always be the Azure DevOps repository.

Usage

  1. Install python packages used for the service

    pip install - requirements.txt
  2. Run the FastAPI server, which will run on port 8000

    python app/main.py

    Endpoint documentation are available on http://127.0.0.1:8000/docs

Docker

Running the docker-compose.yml, will build a new image python-fastapi-azure-k8s-cluster-fastapi:latest which will be used for the fastapi service within the container.

docker-compose up -d

Tests

Unit tests are located in /tests directory.

pytest tests/

Azure Pipelines (CI/CD)

This project has two pipelines see files:

  • /azure-pipelines-docker-k8s-deploy.yml
  • /azure-pipelines-run-unit-tests.yml

The tables below detail pipeline variables required, most of the values required for deploying FastAPI to Azure Kubernetes cluster, can be found with the terraform repository here. Additionally, as the orginasation / projected created, within Azure DevOps is private, these pipelines have been written to run on a self-host build agent so YMMV.

Pipeline variables (docker-k8s-deploy)

Variable Description Default value Required?
projectAzureSubscriptionConnection The Azure Resource Manager service connection ID N/A Yes
projectAzureResourceGroup The Azure resource group were the cluster exists in N/A Yes
projectKubernetesCluster The Azure kubernetes cluster name N/A Yes
projectImagePullSecret The Kubernetes secret name to be generated / used for pulling images from ACR N/A Yes
k8sNamespace The Kubernetes name space to deploy the service default No
projectPoolName The Azure agent pool that the job will run on N/A Yes
projectContainerRegistry The Azure container registry login server N/A Yes
projectDockerRegistryServiceConnection The service connection with Docker Registry (using basic authentication) N/A Yes
projectImageRepository The docker image name to push to registry N/A Yes

Pipeline variables (run-unit-tests)

Variable Description Default value Required?
projectPoolName The Azure agent pool that the job will run on N/A Yes

Footnotes

  1. My Azure DevOps organisation / project is private, terraform repository is mirrored here in GitHub. โ†ฉ

python-fastapi-azure-k8s-cluster's People

Contributors

kwame-mintah avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

solaimalais

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.