Reference example · Python API

FastAPI values.

A Python API release with a migration init container.

values.yaml

replicaCount: 2
image: ghcr.io/example-org/fastapi
imageTag: "1.0.0"
imagePullPolicy: IfNotPresent

service:
  port: 8080

securityContext:
  runAsNonRoot: true
  runAsUser: 10001
  runAsGroup: 10001
  allowPrivilegeEscalation: false
  readOnlyRootFilesystem: true
  capabilities:
    drop: ["ALL"]
podSecurityContext:
  seccompProfile:
    type: RuntimeDefault

env:
  - name: APP_ENV
    value: production
envFrom:
  - configMapRef:
      name: fastapi-config
envSecrets:
  enableEnv: true
  envs:
    - name: DATABASE_URL
      secretName: fastapi-secrets
      secretKey: DATABASE_URL

configMaps:
  - name: fastapi-config
    data:
      LOG_LEVEL: info
      OTEL_SERVICE_NAME: fastapi

initContainers:
  enabled: true
  containers:
    - name: migrations
      image: ghcr.io/example-org/fastapi
      imageTag: "1.0.0"
      command: ["python", "-m", "app.migrations"]
      securityContext:
        runAsNonRoot: true
        runAsUser: 10001
        runAsGroup: 10001
        allowPrivilegeEscalation: false
        capabilities:
          drop: ["ALL"]
      resources:
        requests: {cpu: 25m, memory: 64Mi}
        limits: {cpu: 100m, memory: 128Mi}

resources:
  requests: {cpu: 100m, memory: 128Mi}
  limits: {cpu: 500m, memory: 512Mi}
readinessProbe:
  httpGet: {path: /health, port: http}
livenessProbe:
  httpGet: {path: /health, port: http}
route:
  enabled: true
  gateway: external
  gatewayNamespace: gateway-system
  sectionName: https
  hostname: fastapi.example.com

Deploy

helm upgrade --install fastapi universal/application \
  --namespace apps --create-namespace \
  --values values.yaml

Result

kubectl get pods -l app.kubernetes.io/instance=fastapi
NAME                       READY   STATUS
fastapi-7d6f9c8d9f-abcde   1/1     Running

curl -fsS https://fastapi.example.com/health
{"status":"ok"}

Package

Artifact Hub →