DEV Community

Shakir
Shakir

Posted on • Updated on

HarperDB with Anthos on GKE

Introduction

Anthos is a service from Google cloud using which we can deploy and manage workloads using various options such as cloud run, GKE, self managed clusters, hybrid cloud clusters, edge based workloads and so on. In this post, we would focus on the autopilot GKE based cluster and deploy HarperDB on it with a Helm chart. Please check this link for the helm chart, we use in this post.

Let's get started...

Enable Anthos

Search for Anthos on the Google cloud console and enable the Anthos API.
Search for Anthos

GKE

We would be going with an Anthos managed GKE cluster, so click on the configure option in the auto pilot option.
Auto pilot

I have kept all options to their defaults. Wait for the cluster to get created. The notifications link should show the status of creation.
Notification for cluster creation in progress

We should now have a GKE cluster by name autopilot-cluster-1.
Notification for cluster creation completed

Refresh the page to see the cluster.
Un registered cluster

Register

We have created the GKE cluster via Anthos, however we also need to register it. Click register and go back to the clusters page, the cluster should show under Anthos managed clusters.
Anthos managed cluster

We can now use the GKE cluster to launch any applications in the usual way with kubectl or helm.

Kubeconfig

Go the cloud shell and run the following command to update kubeconfig.

$ gcloud container clusters get-credentials autopilot-cluster-1 --region us-central1
Fetching cluster endpoint and auth data.
kubeconfig entry generated for autopilot-cluster-1.
Enter fullscreen mode Exit fullscreen mode

Both kubectl and helm would use this kubeconfig to interact with the cluster.

Namespace

Let's create a namespace with kubectl.

$ kubectl create ns harperdb
namespace/harperdb created
Enter fullscreen mode Exit fullscreen mode

Helm

We can deploy the Kubernetes objects with Helm, for which let's check if there is any publicly available helm chart for harperdb chart in the artifact hub.

$ helm search hub harperdb
No results found
Enter fullscreen mode Exit fullscreen mode

We don't have a chart yet on the hub. Hence, I would be using a local minimal helm chart, whose files are as follows.

$ ls harperdb -tR
harperdb:
templates  Chart.yaml  values.yaml

harperdb/templates:
svc.yaml  deploy.yaml  pvc.yaml  secret.yaml
Enter fullscreen mode Exit fullscreen mode

For more info on the contents of files in this chart, pl. checkout this post.

Alright, so let's install our helm release on the GKE cluster managed by Anthos.

$ helm install harperdb . -n harperdb
W0114 05:34:47.808566     817 warnings.go:70] Autopilot set default resource requests for Deployment harperdb/harperdb, as resource requests were not specified. See http://g.co/gke/autopilot-defaults
NAME: harperdb
LAST DEPLOYED: Sat Jan 14 05:34:39 2023
NAMESPACE: harperdb
STATUS: deployed
REVISION: 1
TEST SUITE: None
Enter fullscreen mode Exit fullscreen mode

Resources

Though we have not setup any resource requests in the deployment template, the autopilot cluster had enabled it for us. We can check the deployment spec to see what they have set. Note that it's a good practice to mention resource requests and limits in the template.

$ kubectl get deploy harperdb -n harperdb -o jsonpath={.spec.template.spec.containers[].resources} | jq
{
  "limits": {
    "cpu": "500m",
    "ephemeral-storage": "1Gi",
    "memory": "2Gi"
  },
  "requests": {
    "cpu": "500m",
    "ephemeral-storage": "1Gi",
    "memory": "2Gi"
  }
}
Enter fullscreen mode Exit fullscreen mode

Pod

Check the pod status.

$ kubectl get po -n harperdb
NAME                        READY   STATUS    RESTARTS   AGE
harperdb-559d48f4f7-6dftw   1/1     Running   0          6m9s
Enter fullscreen mode Exit fullscreen mode

API test

The pod is running, we can get the service IP and try sending an API call.

$ HDB_API_ENDPOINT_IP=$(kubectl get svc harperdb -n harperdb -o jsonpath={.status.loadBalancer.ingress[0].ip})

$ curl --location --request POST http://${HDB_API_ENDPOINT_IP}:8080 --header 'Content-Type: application/json' --header 'Authorization: Basic YWRtaW46cGFzc3dvcmQxMjM0NQ==' --data-raw '{
    "operation": "create_schema",
    "schema": "prod"
}'
{"message":"schema 'prod' successfully created"}
Enter fullscreen mode Exit fullscreen mode

So our installation went smooth and it's working.

Clean up

The clean up involves four steps. Deleting the helm chart directory from cloudshell rm -rf harperdb.

Unregistering the cluster from the Anthos console.
Unregister cluster

Delete the cluster from the GKE console.
Delete the cluster

Finally disable the Anthos API.

$ gcloud services disable anthos.googleapis.com
Warning: Disabling this service will also automatically disable any running Anthos clusters.

Do you want to continue (y/N)?  y
Enter fullscreen mode Exit fullscreen mode

Summary

So we have seen how to create an autopilot cluster from the Anthos console, installed a helm release for HarperDB on it, and tested it with a sample schema creation. Thank you for reading !!!

Top comments (1)

Collapse
 
margo_hdb profile image
Margo McCabe

Awesome post, thanks Shakir!