supabase-kubernetes icon indicating copy to clipboard operation
supabase-kubernetes copied to clipboard

Improve Edge Function Documentation

Open nickmitchko opened this issue 1 year ago • 4 comments

Improve documentation

Can we provide an example of deploying an edge function?

Link

Chart Documentation

Add a link to the page which needs improvement (if relevant)

Describe the problem

There is no documentation or example on creating an edge function in this chart. While I'd love to supabase functions deploy the client doesn't support connecting to a local improvement.

Describe the improvement

  1. Define how to take an edge function and place it to this chart
  2. Steps to update the config files
  3. Gotcha's etc.

nickmitchko avatar May 03 '24 03:05 nickmitchko

Following up on this issue:

Found that the yaml for the kong-config isn't properly taking the deployment service name.

image

Here is the change that fixed it:

image

nickmitchko avatar May 03 '24 13:05 nickmitchko

Moreover, here is how I configured a map to the functions with a persistent storage class:

values.example.yaml

functions:
  enabled: true
  nodeSelector:
    nodeName: "ai-server-1"
  image:
    tag: v1.41.2
  environment:
    DB_PORT: 5433
    VERIFY_JWT: false
  service:
    type: ClusterIP
    port: 9002
  volumeMounts:
    - name: myfunctions
      mountPath: /home/deno/functions/custom/
  volumes:
  - name: myfunctions

then in templates/functions/functions.config.yaml

# LN:76
const servicePath = `/home/deno/functions/custom/${service_name}`

Finally, to get the functions in there, I deploy it with a kubectl copy:

#!/bin/bash
functionspod=`kubectl get pods -l app.kubernetes.io/name=supabase-functions --output=jsonpath={.items..metadata.name}`
kubectl cp ./supabase/functions/* ${functionspod}:/home/deno/functions/custom/

now I get to the hook as expected and can continue developing

image

nickmitchko avatar May 03 '24 13:05 nickmitchko

Finally, to get the functions in there, I deploy it with a kubectl copy:

#!/bin/bash
functionspod=`kubectl get pods -l app.kubernetes.io/name=supabase-functions --output=jsonpath={.items..metadata.name}`
kubectl cp ./supabase/functions/* ${functionspod}:/home/deno/functions/custom/

But this needs to be run for each pod in which case it would not work with autoscaling, right? Is there a recommended way to persist the functions and update them every time a new version is deployed using GitHub Actions?

One way would be to move all functions into a config map (like this) and mount that map as is done with the main function. But I don't think that's what config maps are meant for and it also does not work if all edge functions exceed 1MB.

I am currently looking into Persistent Volumes, but I am very inexperienced with Kubernetes. Any pointers from someone running this in production would be helpful.

joeldomke avatar May 27 '24 14:05 joeldomke

Finally, to get the functions in there, I deploy it with a kubectl copy:

#!/bin/bash
functionspod=`kubectl get pods -l app.kubernetes.io/name=supabase-functions --output=jsonpath={.items..metadata.name}`
kubectl cp ./supabase/functions/* ${functionspod}:/home/deno/functions/custom/

But this needs to be run for each pod in which case it would not work with autoscaling, right? Is there a recommended way to persist the functions and update them every time a new version is deployed using GitHub Actions?

One way would be to move all functions into a config map (like this) and mount that map as is done with the main function. But I don't think that's what config maps are meant for and it also does not work if all edge functions exceed 1MB.

I am currently looking into Persistent Volumes, but I am very inexperienced with Kubernetes. Any pointers from someone running this in production would be helpful.

As you're inexperienced in kubernetes, check out storage providers for k8s. Many storage providers allow you to configure multi-node access to the same storage. I use an NFS mount for this function which makes it available to all deno pods that spin up. Just make sure that your functions don't do anything filesystem dependent or you can conflict when the pods scale.

nickmitchko avatar May 28 '24 18:05 nickmitchko