Hasura is one of the leading vendors in the GraphQL ecosystem. They offer an open source engine that connects to your databases and microservices, and then auto-generates a production-ready GraphQL backend. GraphQL is a query language (more specifically a specification) for your API, and a server-side runtime for executing queries by using a type system you define for your data. GraphQL is often used for microservices, mobile apps, and as an alternative to REST. Although GraphQL isn’t tied to any specific database or storage engine and is instead backed by your existing code and data, YugabyteDB is a perfect complement to GraphQL giving you horizontal scalability, fault tolerance, and global data distribution in a single system.
In this blog post we’ll show you how to do:
The “realtime location application” is built using React and is powered by Hasura GraphQL Engine backed by a 3 node YugabyteDB cluster. It has an interface for users to track location of a vehicle using Hasura live queries, in real time. The application makes use of Hasura GraphQL Engine’s real-time capabilities using subscription.
New to distributed SQL or YugabyteDB? Read on.
For a deeper discussion about what Distributed SQL is, check out, “What is Distributed SQL?”
YugabyteDB is an open source, high-performance distributed SQL database built on a scalable and fault-tolerant design inspired by Google Spanner. YugabyteDB is PostgreSQL wire compatible, cloud native, offers deep integration with GraphQL projects, plus supports advanced RDBMS features like stored procedures, triggers and UDFs.
In this section we are going to install YugabyteDB on the cluster. The complete steps are documented here. We’ll assume you already have a GKE cluster up and running as a starting point.
The first thing to do is to add the charts repository.
Java
1
$ helm repo add yugabytedb https://charts.yugabyte.com
Now, fetch the updates.
Java
1
$ helm repo update
Create a namespace. In this case we’ll call it yb-demo
.
Java
1
$ kubectl create namespace yb-demo
Expected output:
Java
1
namespace/yb-demo created
We are now ready to install YugabyteDB. In the command below we’ll be specifying values for a resource constrained environment.
Java
1
$ helm install yb-demo yugabytedb/yugabyte \
2
--set resource.master.requests.cpu=1,resource.master.requests.memory=1Gi,\
3
resource.tserver.requests.cpu=1,resource.tserver.requests.memory=1Gi,\
4
enableLoadBalancer=True --namespace yb-demo --wait
To check the status of the cluster, execute the below command:
Java
1
$ kubectl get services --namespace yb-demo
Note: the external-IP for yb-tserver-service
which we are going to use to establish a connection between YugabyteDB and Hasura. In this demo, the IP is 35.224.XX.XX
and the YSQL port is 5433
.
Get the Hasura Kubernetes deployment and service files by executing the commands below.
Java
1
$ wget https://raw.githubusercontent.com/hasura/graphql-engine/master/install-manifests/kubernetes/deployment.yaml
Java
1
$ wget https://raw.githubusercontent.com/hasura/graphql-engine/master/install-manifests/kubernetes/svc.yaml
Modify the database URL in deployment.yaml
file to include the IP of YugabyteDB. This file can be edited using a text editor like vi. Note that by default the yugabyte
user in YugabyteDB doesn’t have a password and the default database is yugabyte
.
For the purposes of this tutorial, the modification should look like this:
Java
1
value: postgres://yugabyte:@35.224.XX.XX:5433/yugabyte
Note: If you’d like everything to run in the yb-demo
namespace, make sure to modify the namespace value in both the deployment.yaml
and svc.yaml
files. This is the setup I have chosen for this demo.
After saving the file use kubectl
to create a Hasura deployment using the commands below:
Java
1
$ kubectl create -f deployment.yaml
2
3
deployment.apps/hasura created
Java
1
$ kubectl create -f svc.yaml
2
3
service/hasura created
To find the external IP and open the Hasura console execute the command below:
Java
1
$ kubectl get services --namespace yb-demo
Now use http://<EXTERNAL-IP>/console
to access the Hasura console. In this case it is 34.68.XX.XX
. You should now see the Hasura console.
#tutorial #kubernetes #postgresql #graphql #distributed sql #sql