Skip to content

This repository contains a Helm chart for a FastAPI application to be deployed on OpenShift clusters with minimal effort with customizable configurations.

License

Notifications You must be signed in to change notification settings

anqorithm/fastapi-helm-chart

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FastAPI Helm Chart

Artifact Hub Helm Version OpenShift Version Kubernetes FastAPI Docker Poetry License GitHub last commit GitHub issues GitHub pull requests GitHub contributors GitHub forks GitHub stars GitHub watchers

FastAPI Helm Chart

This repository contains a Helm chart for a FastAPI application to be deployed on OpenShift clusters with minimal effort with customizable configurations.

Prerequisites

  • Helm CLI (version 3+)
  • OpenShift Cluster (version 4.x recommended)
  • Docker (for building application images)
  • Poetry (for Python dependency management)

Checking version

Configuration

The following tables describe the configurable parameters of the FastAPI Helm chart. You can override these values by creating your own values.yaml file.

Core Configuration

Parameter Description Default
replicaCount Number of replicas of the FastAPI application 1

Image Configuration

Parameter Description Default
image.registry Docker registry for the FastAPI image ""
image.repository Docker image repository ""
image.tag Docker image tag ""
image.pullPolicy Image pull policy (Always, IfNotPresent, Never) IfNotPresent
imagePullSecrets Image pull secrets for private registries []

Network Configuration

Parameter Description Default
service.type Kubernetes service type (ClusterIP, LoadBalancer, NodePort) ClusterIP
service.port Service port for accessing the application 80

Environment Variables (ConfigMap)

You can define as many environment variables as needed in the configMap. The chart comes with some default FastAPI application environment variables. These variables will be available to your FastAPI application at runtime.

Parameter Description Default
configMap.data.APP_NAME Name of the FastAPI application "Example FastAPI App"
configMap.data.DEBUG Enable debug mode (true/false) false
configMap.data.VERSION Application version "0.1.0"

To add or modify environment variables, you can update the configMap.data section in your values.yaml file. For example:

configMap:
  data:
    APP_NAME: "My FastAPI Application"
    DEBUG: "false"
    VERSION: "1.0.0"
    CUSTOM_VAR: "custom-value"  # Add your custom variables here

OpenShift Route Configuration

Parameter Description Default
route.enabled Enable OpenShift route for external access false
route.host Route hostname (e.g., myapp.apps.cluster.com) ""
route.path Route path /
route.tls.enabled Enable TLS for secure routes false
route.tls.termination TLS termination type (edge, passthrough, reencrypt) edge
route.tls.insecureEdgeTerminationPolicy How to handle insecure traffic Allow

Resource Management

Parameter Description Default
resources.limits.cpu Maximum CPU allocation ""
resources.limits.memory Maximum memory allocation ""
resources.requests.cpu Minimum CPU requirement ""
resources.requests.memory Minimum memory requirement ""

Scheduling Configuration

Parameter Description Default
nodeSelector Node labels for pod assignment {}
tolerations Pod tolerations for node taints []
affinity Pod affinity/anti-affinity rules {}

Build the Docker image

Build

docker build -t {YOUR_DOCKER_REGISTRY}/{YOUR_DOCKER_IMAGE_NAME}:{YOUR_DOCKER_TAG} .

Build

Tag

docker tag {YOUR_DOCKER_IMAGE_NAME}:{YOUR_DOCKER_TAG} {YOUR_DOCKER_REGISTRY}/{YOUR_DOCKER_IMAGE_NAME}:{YOUR_DOCKER_TAG}

Tag

Push

docker push {YOUR_DOCKER_REGISTRY}/{YOUR_DOCKER_IMAGE_NAME}:{YOUR_DOCKER_TAG}

Push

Example of Implemented Values.yaml file

# Number of application replicas to run
replicaCount: 1

# Container image configuration
image:
  repository: {YOUR_DOCKER_REGISTRY}  # e.g., quay.io/myorg/myapp
  tag: {YOUR_DOCKER_TAG}  # e.g., latest, v1.0.0
  pullPolicy: {YOUR_DOCKER_PULL_POLICY}  # Usually IfNotPresent or Always

# Secrets for pulling images from private registries
imagePullSecrets:
  - name: {YOUR_IMAGE_PULL_SECRET_NAME}

# Optional name overrides
nameOverride: ""
fullnameOverride: ""

# Service configuration for accessing your application
service:
  type: LoadBalancer  # Can be ClusterIP, LoadBalancer, or NodePort
  port: 80  # Port your service will listen on

# Environment variables for your application
configMap:
  data:
    APP_NAME: {YOUR_APP_NAME}  # e.g., "My FastAPI App"
    DEBUG: {YOUR_DEBUG_VALUE}  # e.g., "false"
    VERSION: {YOUR_VERSION}  # e.g., "1.0.0"
    # Add your custom environment variables here

# Resource limits and requests
resources:
  limits:
    cpu: 100m  # 100 millicores = 0.1 CPU
    memory: 128Mi  # 128 megabytes
  requests:
    cpu: 100m
    memory: 128Mi

# Pod scheduling configurations
nodeSelector: {}  # Add node selectors if needed

tolerations: []  # Add tolerations if needed

affinity: {}  # Add affinity rules if needed

Add the repository to your Helm CLI

helm repo add fastapi-helm-chart https://anqorithm.github.io/fastapi-helm-chart/charts/fastapi

Install the chart

helm install my-fastapi-helm-chart fastapi-helm-chart/fastapi-helm-chart --version 0.0.4

Installation

To install the chart with the release name "fastapi-chart":

Clone the repository

git clone https://github.com/anqorithm/fastapi-helm-chart.git

Install the chart

helm install fastapi-chart ./charts/fastapi

Install

Open OpenShift to see the application

OpenShift

Create a route to access the application

Route

Access the application

Access

Access

This will deploy your FastAPI application to the OpenShift cluster using the default configuration values. For custom configurations, create a values.yaml file with your desired settings and use:

helm install fastapi-chart ./charts/fastapi -f values.yaml

Contributing

Contributions are welcome! Please feel free to submit a PR.

Contributors

License

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

Acknowledgments

About

This repository contains a Helm chart for a FastAPI application to be deployed on OpenShift clusters with minimal effort with customizable configurations.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published