Supabase

How to use Supabase with Kubernetes?

Discover the ins and outs of deploying, managing, and scaling Supabase using Kubernetes to ensure strong and effective backend services. Get guided through each step. Dive into the details.

Developer profile skeleton
a developer thinking

Overview

Deploying Supabase on Kubernetes means setting up Supabase services—like the database, authentication, storage, and real-time APIs—in a way that’s both scalable and containerized. By doing this, it becomes easier to use Kubernetes' orchestration features for managing, scaling, and keeping your Supabase backend highly available. To pull this off, a good grasp of Kubernetes concepts such as pods, services, and ingress controllers is essential. Creating Kubernetes manifests to outline your Supabase components is key. This integration can boost your workflow, providing a solid and cloud-native backend solution.

Get a Free No-Code Consultation
Meet with Will, CEO at Bootstrapped to get a Free No-Code Consultation
Book a Call
Will Hawkins
CEO at Bootstrapped

How to use Supabase with Kubernetes?

Step 1: Set Up Your Kubernetes Cluster

First things first, make sure you have a working Kubernetes cluster. You can go with managed services like Google Kubernetes Engine (GKE), Amazon Elastic Kubernetes Service (EKS), or Azure Kubernetes Service (AKS). If you're just tinkering around, a local setup using minikube or kind works just fine too.

Step 2: Install kubectl

Next up, you'll need kubectl to interact with your Kubernetes cluster. If you don't have it yet, here's how to get it:

# macOS users
brew install kubernetes-cli

# Ubuntu users
sudo snap install kubectl --classic

# Windows users using choco
choco install kubernetes-cli

Once installed, configure kubectl to connect to your Kubernetes cluster.

Step 3: Install Helm

Now, let's get Helm, the package manager for Kubernetes.

# macOS users
brew install helm

# Ubuntu users
sudo snap install helm --classic

# Windows users using choco
choco install kubernetes-helm

Step 4: Create a Namespace

Create a namespace in your Kubernetes cluster to keep your Supabase components organized.

kubectl create namespace supabase

Step 5: Configure Supabase Components

Time to set up the Supabase components. You'll need to create Kubernetes configuration files for PostgreSQL, REST API, Realtime, Storage, and Auth.

PostgreSQL Config:

Create a postgresql-deployment.yaml file:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: supabase-postgresql
  namespace: supabase
spec:
  replicas: 1
  selector:
    matchLabels:
      app: supabase-postgresql
  template:
    metadata:
      labels:
        app: supabase-postgresql
    spec:
      containers:
        - name: postgres
          image: postgres:13
          env:
            - name: POSTGRES_USER
              value: "supabase_admin"
            - name: POSTGRES_PASSWORD
              value: "your_password"
            - name: POSTGRES_DB
              value: "supabase_db"
          ports:
            - containerPort: 5432

Deploy it:

kubectl apply -f postgresql-deployment.yaml

Step 6: Deploy Supabase REST API

Create a supabase-rest-api-deployment.yaml file:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: supabase-rest-api
  namespace: supabase
spec:
  replicas: 1
  selector:
    matchLabels:
      app: supabase-rest-api
  template:
    metadata:
      labels:
        app: supabase-rest-api
    spec:
      containers:
        - name: rest-api
          image: postgrest/postgrest
          env:
            - name: PGRST_DB_URI
              value: "postgres://supabase_admin:your_password@supabase-postgresql:5432/supabase_db"
            - name: PGRST_DB_SCHEMA
              value: "public"
            - name: PGRST_DB_ANON_ROLE
              value: "anon"
          ports:
            - containerPort: 3000

Deploy it:

kubectl apply -f supabase-rest-api-deployment.yaml

Step 7: Deploy Supabase Realtime

Create a supabase-realtime-deployment.yaml file:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: supabase-realtime
  namespace: supabase
spec:
  replicas: 1
  selector:
    matchLabels:
      app: supabase-realtime
  template:
    metadata:
      labels:
        app: supabase-realtime
    spec:
      containers:
        - name: realtime
          image: supabase/realtime
          env:
            - name: DB_HOST
              value: "supabase-postgresql"
            - name: DB_NAME
              value: "supabase_db"
            - name: DB_USER
              value: "supabase_admin"
            - name: DB_PASSWORD
              value: "your_password"
            - name: DB_PORT
              value: "5432"
            - name: PORT
              value: "4000"
            - name: SECRET_KEY_BASE
              value: "your_secret_key_base"
          ports:
            - containerPort: 4000

Deploy it:

kubectl apply -f supabase-realtime-deployment.yaml

Step 8: Deploy Supabase Storage

Create a supabase-storage-deployment.yaml file:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: supabase-storage
  namespace: supabase
spec:
  replicas: 1
  selector:
    matchLabels:
      app: supabase-storage
  template:
    metadata:
      labels:
        app: supabase-storage
    spec:
      containers:
        - name: storage
          image: supabase/storage-api
          env:
            - name: POSTGREST_URL
              value: "http://supabase-rest-api:3000"
            - name: POSTGREST_JWT_SECRET
              value: "your_jwt_secret"
            - name: DATABASE_URL
              value: "postgres://supabase_admin:your_password@supabase-postgresql:5432/supabase_db"
            - name: FILE_STORAGE_BACKEND
              value: "file"
            - name: STORAGE_LOCAL_PATH
              value: "/var/storage"
          volumeMounts:
            - mountPath: /var/storage
              name: storage-volume
          ports:
            - containerPort: 5000
      volumes:
        - name: storage-volume
          emptyDir: {}

Deploy it:

kubectl apply -f supabase-storage-deployment.yaml

Step 9: Deploy Supabase Auth

Create a supabase-auth-deployment.yaml file:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: supabase-auth
  namespace: supabase
spec:
  replicas: 1
  selector:
    matchLabels:
      app: supabase-auth
  template:
    metadata:
      labels:
        app: supabase-auth
    spec:
      containers:
        - name: auth
          image: supabase/gotrue
          env:
            - name: GOTRUE_DATABASE_URL
              value: "postgres://supabase_admin:your_password@supabase-postgresql:5432/supabase_db"
            - name: GOTRUE_JWT_SECRET
              value: "your_jwt_secret"
            - name: SITE_URL
              value: "http://localhost" # Or your public facing URL
          ports:
            - containerPort: 8000

Deploy it:

kubectl apply -f supabase-auth-deployment.yaml

Step 10: Expose Services

Create service files to expose the deployments.

For example, for PostgreSQL:

apiVersion: v1
kind: Service
metadata:
  name: supabase-postgresql
  namespace: supabase
spec:
  selector:
    app: supabase-postgresql
  ports:
    - protocol: TCP
      port: 5432
      targetPort: 5432

Deploy the service:

kubectl apply -f postgresql-service.yaml

Repeat similar steps for exposing the rest of Supabase components.

Step 11: Access Your Supabase Components

Use kubectl port-forward to access your Supabase services locally.

kubectl port-forward svc/supabase-postgresql 5432:5432 -n supabase
kubectl port-forward svc/supabase-rest-api 3000:3000 -n supabase
kubectl port-forward svc/supabase-realtime 4000:4000 -n supabase
kubectl port-forward svc/supabase-storage 5000:5000 -n supabase
kubectl port-forward svc/supabase-auth 8000:8000 -n supabase

Explore more Supabase tutorials

Complete Guide to Supabase: Tutorials, Tips, and Best Practices

Explore our Supabase tutorials directory - an essential resource for learning how to create, deploy and manage robust server-side applications with ease and efficiency.

Why are companies choosing Bootstrapped?

40-60%

Faster with no-code

Nocode tools allow us to develop and deploy your new application 40-60% faster than regular app development methods.

90 days

From idea to MVP

Save time, money, and energy with an optimized hiring process. Access a pool of experts who are sourced, vetted, and matched to meet your precise requirements.

1 283 apps

built by our developers

With the Bootstrapped platform, managing projects and developers has never been easier.

hero graphic

Our capabilities

Bootstrapped offers a comprehensive suite of capabilities tailored for startups. Our expertise spans web and mobile app development, utilizing the latest technologies to ensure high performance and scalability. The team excels in creating intuitive user interfaces and seamless user experiences. We employ agile methodologies for flexible and efficient project management, ensuring timely delivery and adaptability to changing requirements. Additionally, Bootstrapped provides continuous support and maintenance, helping startups grow and evolve their digital products. Our services are designed to be affordable and high-quality, making them an ideal partner for new ventures.

Engineered for you

1

Fast Development: Bootstrapped specializes in helping startup founders build web and mobile apps quickly, ensuring a fast go-to-market strategy.

2

Tailored Solutions: The company offers customized app development, adapting to specific business needs and goals, which ensures your app stands out in the competitive market.

3

Expert Team: With a team of experienced developers and designers, Bootstrapped ensures high-quality, reliable, and scalable app solutions.

4

Affordable Pricing: Ideal for startups, Bootstrapped offers cost-effective development services without compromising on quality.

5

Supportive Partnership: Beyond development, Bootstrapped provides ongoing support and consultation, fostering long-term success for your startup.

6

Agile Methodology: Utilizing agile development practices, Bootstrapped ensures flexibility, iterative progress, and swift adaptation to changes, enhancing project success.

Yes, if you can dream it, we can build it.