Installing Hasura on GKE

This section describes:

  1. How to setup a Hasura cluster on GKE
  2. How to add that Hasura cluster to a Hasura project

Set up a GKE cluster

Your GKE cluster needs to have a few things set up before the Hasura platform can be installed on it. The following are the necessary pieces to be set up and configured:

Navigate to your Google Cloud Console

  1. From the Kubernetes Engine section, create a new Kubernetes Cluster in whichever region you prefer. We’ll select the region asia-east1-a and name the cluster as myco-hasura.

  2. From the Compute Engine > Disks section, create 3 disks:

    1. myco-hasura-postgres
    2. myco-hasura-redis
    3. myco-hasura-filestore

    Make sure that they are large enough to hold your data (min 10 GB each), located in the same region as your Kubernetes cluster, the Source type option is set to None (blank disk) and preferably are SSDs.

  3. From the VPC Network > External IP Addresses section, reserve a static IP address in the same region as the Kubernetes cluster (no need to attach to any particular pool).

  4. Map your domain (let’s call it myco-hasura.my-domain.com) to this IP from your DNS provider’s dashboard by creating an A record.

Get the credentials for the GKE cluster

Set up the kube context using the gcloud container clusters get-credentials ... command from the Kubernetes Engine console.

Note the context set by this command since we’ll be needing it later. Use kubectl config current-context (or get-contexts) and note the context.

Installing the Hasura platform

Create cluster-data.yaml

Create a file named cluster-data.yaml with the content as shown below. This file defines a cluster.

cluster-data.yaml
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
name: myco-hasura # insert cluster name
alias: hasura # insert the cluster alias which will be used by hasura cli
data: null
kubeContext: gke_hasura-test_asia-east1-a_myco-hasura # insert kubeContext
config:
  namespace: hasura
  configmap: controller-conf
metadata:
  gateway:
    loadBalancerIP: 11.22.33.44 # insert IP
    ports:
    - name: http
      port: 80
      protocol: TCP
      targetPort: 80
    - name: https
      port: 443
      protocol: TCP
      targetPort: 443
    - name: ssh
      port: 22
      protocol: TCP
      targetPort: 22
    selector:
      app: gateway
    type: LoadBalancer
  namespaces:
    hasura: hasura
    user: default
  postgres:
    volume:
      gcePersistentDisk:
        pdName: myco-hasura-postgres # insert postgres disk name
      name: postgres-pv
  filestore:
    volume:
      gcePersistentDisk:
        pdName: myco-hasura-filestore # insert filestore disk name
      name: filestore-pv
  sessionStore:
    volume:
      gcePersistentDisk:
        pdName: myco-hasura-redis # insert redis disk name
      name: redis-pv
  registry: null

We’re now ready to install the Hasura platform on the myco-hasura cluster!

Install the Hasura platform

To install the Hasura platform, run:

$ hasura cluster install --file cluster-data.yaml --domain myco-hasura.my-domain.com

Wait for some time for all the components of the cluster to come up. You may use kubectl get pods -n hasura to see if all the pods are up.

Setup a local project

If you have an existing Hasura project, skip to the cluster add part.

Clone the base repo from Hasura Hub into a local directory:

$ hasura clone hasura/base

Add the cluster

To add this cluster to the project,

$ cd [project-directory]
$ hasura cluster add --file=/path/to/cluster-data.yaml

This will add the cluster defined in cluster-data.yaml to the current project, sets up required remotes, hooks and ssh keys.

Deploy project to the cluster

Finally push your project to the newly created cluster:

$ git push myco-hasura master

Tearing down

You can delete all the resources Hasura created by executing the following commands:

kubectl delete namespace hasura
kubectl delete configmap hasura-conf hasura-status ssh-authorized-keys
kubectl delete secret hasura-secrets
kubectl delete clusterrolebinding hasura-cluster-admin-binding

# Next, delete all the infrastructure components like disks, ip address etc.

Note

The Hasura Kubernetes Platform is available under these Terms of Service.