Supabase Kubernetes

repository·main·Indexed 18 days ago

https://github.com/supabase-community/supabase-kubernetes

Kubernetes-native deployments for the Supabase stack. Provides two primary installation methods: a dedicated Kubernetes Operator using Custom Resources (Project, SingleDatabase, Function, Migration) and traditional Helm charts. Features include support for S3 storage, BigQuery analytics, component autoscaling, and automated database migrations via db.config.

Tokens
5.8K
Snippets
29
Records
37
Agent score
74%

What's inside supabase-kubernetes

  1. Overview of Supabase Kubernetes deployment approaches

    main

    There are two primary ways to run Supabase on a Kubernetes cluster:

    1. Supabase Kubernetes Operator: A Kubernetes-native approach using Custom Resources (core.supabase.io/v1alpha1). This allows you to manage Supabase through modular resources. Note that the Operator is in early development and its API may change.
    2. Supabase Helm Chart: A traditional deployment method using Helm charts. Detailed information can be found in the charts/supabase directory.
  2. How the Supabase Kubernetes Operator works

    main

    The Operator manages Supabase via several Kubernetes Custom Resources (CRDs). This modular design allows you to enable only the specific components your project requires.

    Supported Custom Resources:

    • Project (projects): Represents a complete Supabase instance.
    • SingleDatabase (singledatabases): A Postgres database managed by the Operator.
    • Function (functions): Edge Functions deployed within the cluster.
    • Migration (migrations): Used to apply SQL scripts to databases or manage internal Supabase upgrade migrations.
  3. Deploy a Supabase Project

    main

    Use the supabase-project chart to create a SingleDatabase and a Project resource. You must provide specific configuration values for hostnames, ports, and authentication URLs. The Operator will then automatically provision the Postgres StatefulSet, component Deployments, Services, Secrets, and run sync Jobs for JWT and database configuration.

    helm install supabase supabase/supabase-project \
      --set fullnameOverride=supabase \
      --set project.http.hostname=localhost \
      --set project.http.port=8000 \
      --set auth.siteUrl=http://localhost:3000 \
      --set studio.orgName="Default Organization" \
      --set studio.projName="Default Project"
  4. Deploy the Supabase Operator

    main

    Install the Operator into the supabase-operator namespace. This command installs the necessary Custom Resource Definitions (CRDs) and deploys the controller in a single step.

    helm install supabase-operator supabase/supabase-operator \
      --namespace supabase-operator \
      --create-namespace
  5. Quick Start for Local Development

    main

    To run the Supabase Kubernetes Operator locally for development, use a Kind cluster. This sequence sets up the cluster, generates the necessary code and manifests, installs the CRDs, and starts the controller.

    Note: Ensure you have kubectl configured and Kind installed before starting.

    make kind-up
    make generate
    make manifests
    make install
    make run
    kubectl apply -k config/samples
  6. Quick Start: Install Supabase via Helm

    main

    To run a local development instance of Supabase using Minikube and Helm, follow these steps:

    1. Prepare Minikube: Start a cluster with the Docker driver and enable the ingress addon. Map supabase.local to your Minikube IP in /etc/hosts.
    2. Add Helm Repo: Add the supabase repository to your Helm client.
    3. Install: Run helm install with a release name (e.g., demo).
    4. Verify: Monitor the pods using kubectl. Note that the first deployment (especially the auth service) may take time.
    5. Access: Open Supabase Studio at http://supabase.local.

    Default Credentials (Local Dev Only):

    • Username: supabase
    • Password: this_password_is_insecure_and_should_be_updated
    # 1. Setup Minikube
    minikube start --driver=docker
    minikube addons enable ingress
    echo "$(minikube ip)     supabase.local" | sudo tee -a /etc/hosts > /dev/null
    
    # 2. Add Helm repo
    helm repo add supabase https://supabase-community.github.io/supabase-kubernetes
    
    # 3. Install
    helm install demo supabase/supabase
    
    # 4. Check status
    kubectl get pod -l app.kubernetes.io/instance=demo
  7. Run Database Migrations during Initialization

    main

    You can automate database schema migrations by adding them to the db.config field. Any SQL scripts provided here will be applied during the database initialization process. Use the multi-line YAML syntax (|) to include the SQL content.

    db:
      config:
        20230101000000_profiles.sql: |
          create table profiles (
            id uuid references auth.users not null,
            username text unique
          );
  8. Override Environment Variables

    main

    Starting with chart version 0.7.1, environment.<component> is an array of Kubernetes env entries. Each entry supports value: or valueFrom:.

    User-provided entries are rendered after the chart defaults, allowing you to override any chart-managed environment variable by providing an entry with the same name.

    environment:
      auth:
        - name: GOTRUE_API_HOST
          value: "0.0.0.0"
        - name: GOTRUE_EXTERNAL_AZURE_SECRET
          valueFrom:
            secretKeyRef:
              name: azure-secret
              key: secret