On Google Cloud Platform and Kubernetes​

In this guide we show how to deploy EdgeDB on GCP using Cloud SQL and Kubernetes.

Prerequisites​

Make sure you are logged into google cloud.

  1. gcloud init

Create a project​

If you already have a project you can use your existing project.

  1. PROJECT=edgedb
  1. gcloud projects create $PROJECT

Choose a name​

We’ll add suffixes to this name to create names for each component in the deployment.

  1. NAME=edgedb

Provision a Postgres instance​

Choose your own secure ADMIN_PASSWORD. This will be the password for both popostgres and EdgeDB.

  1. read -rsp "Admin Password: " ADMIN_PASSWORD
  1. gcloud services enable container.googleapis.com \
  2. --project=$PROJECT
  1. gcloud sql instances create ${NAME}-postgres \
  2. --database-version=POSTGRES_13 \
  3. --cpu=1 \
  4. --memory=3840MiB \
  5. --region=us-west2 \
  6. --project=$PROJECT
  1. gcloud sql users set-password postgres \
  2. --instance=${NAME}-postgres \
  3. --password=$ADMIN_PASSWORD \
  4. --project=$PROJECT

Create a Kubernetes cluster​

Before creating the cluster be sure that the Kubernetes Engine API is enabled .

  1. gcloud services enable container.googleapis.com \
  2. --project=$PROJECT

Create a cluster.

  1. gcloud container clusters create ${NAME}-k8s \
  2. --zone=us-west2-a \
  3. --num-nodes=1 \
  4. --project=$PROJECT

Configure Cloud SQL proxy credentials​

  1. gcloud services enable iam.googleapis.com \
  2. --project=$PROJECT
  1. gcloud iam service-accounts create ${NAME}-account \
  2. --project=$PROJECT
  1. gcloud services enable sqladmin.googleapis.com \
  2. --project=$PROJECT
  1. MEMBER="serviceAccount:${NAME}-account@${PROJECT}.iam.gserviceaccount.com"
  1. gcloud projects add-iam-policy-binding $PROJECT \
  2. --member=$MEMBER \
  3. --role=roles/cloudsql.admin \
  4. --project=$PROJECT
  1. gcloud iam service-accounts keys create credentials.json \
  2. --iam-account=${NAME}-account@${PROJECT}.iam.gserviceaccount.com
  1. kubectl create secret generic cloudsql-instance-credentials \
  2. --from-file=credentials.json=credentials.json
  1. INSTANCE_CONNECTION_NAME=$(
  2. gcloud sql instances describe ${NAME}-postgres \
  3. --format="value(connectionName)" \
  4. --project=$PROJECT
  5. )
  1. DSN="postgresql://postgres:${ADMIN_PASSWORD}@127.0.0.1:5432"
  1. kubectl create secret generic cloudsql-db-credentials \
  2. --from-literal=dsn=$DSN \
  3. --from-literal=password=$ADMIN_PASSWORD \
  4. --from-literal=instance=${INSTANCE_CONNECTION_NAME}=tcp:5432

Deploy EdgeDB​

  1. wget "https://raw.githubusercontent.com\
  2. /edgedb/edgedb-deploy/dev/gcp/deployment.yaml"
  1. kubectl apply -f deployment.yaml

Ensure the pods are running. It may take a minute for the first boot to finish.

  1. kubectl get pods

If there were errors you can check EdgeDB’s logs with:

  1. kubectl logs deployment/edgedb --container edgedb

Persist TLS Certificate​

  1. kubectl create secret generic cloudsql-tls-credentials \
  2. --from-literal=tlskey="$(
  3. kubectl exec deploy/edgedb -c=edgedb -- \
  4. edgedb-show-secrets.sh --format=raw EDGEDB_SERVER_TLS_KEY
  5. )" \
  6. --from-literal=tlscert="$(
  7. kubectl exec deploy/edgedb -c=edgedb -- \
  8. edgedb-show-secrets.sh --format=raw EDGEDB_SERVER_TLS_CERT
  9. )"
  1. kubectl delete -f deployment.yaml
  1. kubectl apply -f deployment.yaml

Expose EdgeDB​

  1. kubectl expose deploy/edgedb --type LoadBalancer
  1. echo $ADMIN_PASSWORD | edgedb instance link \
  2. --password-from-stdin \
  3. --non-interactive \
  4. --trust-tls-cert \
  5. --host "$(
  6. kubectl get service \
  7. --template="{{
  8. range .items}}{{
  9. if eq .spec.type \"LoadBalancer\"}}{{
  10. range .status.loadBalancer.ingress}}{{
  11. .ip}}{{
  12. end}}{{
  13. end}}{{
  14. end}}"
  15. )" \
  16. google
  1. edgedb -I google