{{announcement.body}}
{{announcement.title}}

Getting Started With Distributed SQL on Azure Kubernetes Service

DZone 's Guide to

Getting Started With Distributed SQL on Azure Kubernetes Service

Get the Northwind sample database running on top of distributed SQL and Azure Kubernetes Service, step-by-step

· Database Zone ·
Free Resource

Microsoft’s Azure Kubernetes Service (AKS) offers a highly available, secure, and fully managed Kubernetes service for developers looking to host their applications on containers in the cloud. AKS features elastic provisioning, an integrated developer experience for rapid application development, enterprise security features, and the most available regions of any cloud provider.

YugabyteDB is a natural fit for AKS because it was designed to support cloud native environments since its initial design.

YugabyteDB is an open source, high-performance distributed SQL database built on a scalable and fault-tolerant design inspired by Google Spanner. Yugabyte’s SQL API (YSQL) is PostgreSQL wire compatible.

If your organization is looking to build an application that requires Kubernetes support, geo distributed data, high performance and availability, plus the familiarity of SQL, then YugabyteDB should be in the top on your shortlist of databases to use as a backend.

In this blog post, we’ll show you how easy it is to get started with YugabyteDB on AKS in just a few minutes. As a bonus, we’ll also show you how to deploy the familiar Northwind sample database.

Prerequisites

Below is a list of the various components we’ll be installing and configuring for the purposes of this post:

To get YugabyteDB up and running on an Azure Kubernetes cluster we’ll need to perform the following steps:

  • Step 1: Install the Azure CLI
  • Step 2: Create a resource group
  • Step 3: Create a Kubernetes cluster
  • Step 4: Install YugabyteDB
  • Bonus: Install the Northwind sample database

Step 1: Install the Azure CLI

Before we create our Kubernetes cluster, let’s first install the Azure CLI on our local machine. To install the Azure CLI on your operating system follow the instructions in the link here.

On Mac, you can install the CLI via Homebrew with:

Java
 




x


 
1
$ brew update && brew install azure-cli



Once installed, login at the command line with:

Java
 




xxxxxxxxxx
1


 
1
$ az login



…or open up a browser page at https://aka.ms/devicelogin and enter the authorization code displayed in your terminal. You should now be able to access the Azure Portal UI by going to https://portal.azure.com/..

Step 2: Create a Resource Group

To create a resource group, we’ll need to first choose the location where it will be hosted. Run the following command to retrieve a list of the available locations:

Java
 




xxxxxxxxxx
1


 
1
$ az account list-locations



For the purposes of this demo we are going to choose the “West US” location.

Java
 




xxxxxxxxxx
1


 
1
 {
2
    "displayName": "West US",
3
    "id": "/subscriptions/53f36dd9-85d8-4690-b45b-92733d97e6c3/locations/westus",
4
    "latitude": "37.783",
5
    "longitude": "-122.417",
6
    "name": "westus",
7
    "subscriptionId": null
8
  },



Next, create the resource group by running the following command using whatever location you decided on:

Java
 




xxxxxxxxxx
1
13


 
1
$ az group create --name yugabytedbRG --location westus
2
 
          
3
{
4
  "id": "/subscriptions/53f36dd9-85d8-4690-b45b-92733d97e6c3/resourceGroups/yugabytedbRG",
5
  "location": "westus",
6
  "managedBy": null,
7
  "name": "yugabytedbRG",
8
  "properties": {
9
    "provisioningState": "Succeeded"
10
  },
11
  "tags": null,
12
  "type": "Microsoft.Resources/resourceGroups"
13
}



You should now be able to view the “yugabytedbRG” resource group in the Azure Portal by clicking on Resource Groups.

Step 3: Create the Kubernetes Cluster

We can now create our Kubernetes cluster by running the following command. Note that we have not specified any zones in the command below which means the AKS control plane components for the cluster will essentially be deployed in a single zone.

Java
 




xxxxxxxxxx
1


 
1
$ az aks create \
2
--resource-group yugabytedbRG \
3
--name yugabytedbAKSCluster \
4
--node-count 3 \
5
--node-vm-size Standard_D2s_v3 \
6
--enable-addons monitoring \
7
--generate-ssh-keys



The --generate-ssh-keys argument auto-generates SSH public and private key files that will be stored in the ~/.ssh directory.

You should see the following output:

Java
 




xxxxxxxxxx
1


 
1
Finished service principal creation[###################]  100.0000%
2
 - Running ..



We should now see ”yugabytedbAKSCluster” in the UI.

To create the cluster and use your own ssh keys, run the following command:

Java
 




xxxxxxxxxx
1


 
1
$ ssh-keygen -t rsa -b 2048



Follow the prompts to create the id_rsa and id_rsa.pub files and note the location where they are stored. Now, execute:

Java
 




xxxxxxxxxx
1


 
1
$ az aks create \
2
--resource-group yugabytedbRG \
3
--name yugabytedbAKSCluster \
4
--node-count 3 \
5
--node-vm-size Standard_D2s_v3 \
6
--enable-addons monitoring \
7
--ssh-key-value <path_to>id_rsa.pub



Once the cluster is installed, point kubectl to the cluster by running the following command:

Java
 




xxxxxxxxxx
1


 
1
$ az aks get-credentials --resource-group yugabytedbRG --name yugabytedbAKSCluster



You should see output similar to:

Java
 




xxxxxxxxxx
1


 
1
Merged "yugabytedbAKSCluster" as current context in /Users/jguerrero/.kube/config



If you generated your own ssh-keys, point kubectl to the cluster by running the following command instead:

Java
 




xxxxxxxxxx
1


 
1
$ az aks get-credentials --resource-group yugabytedbRG --name yugabytedbAKSCluster -ssh-key-file <path_to>id_rsa



Verify that the cluster nodes are running using the following command:

Java
 




xxxxxxxxxx
1


 
1
$ kubectl get nodes



You should see output similar to:

You can also view the details of the cluster in the Kubernetes Dashboard by running the following commands:

Java
 




xxxxxxxxxx
1


 
1
$ kubectl create clusterrolebinding kubernetes-dashboard --clusterrole=cluster-admin --serviceaccount=kube-system:kubernetes-dashboard
2
 
          
3
$ az aks browse --resource-group yugabytedbRG --name yugabytedbAKSCluster



Running the command above will open a browser window where you can view the Kubernetes dashboard:

Step 4: Install YugabyteDB Using Helm Chart

Now that we have our Kubernetes cluster up and running, we’ll need to perform the following steps to get YugabyteDB deployed:

  • Add the YugabyteDB Helm repo
  • Create a namespace
  • Install YugabyteDB using Helm

Let’s first add the YugabyteDB repo by running the following commands:

Java
 




xxxxxxxxxx
1
13


 
1
$ helm repo add yugabytedb https://charts.yugabyte.com
2
 
          
3
"yugabytedb" has been added to your repositories
4
 
          
5
$ helm repo update
6
 
          
7
Hang tight while we grab the latest from your chart repositories...
8
...Successfully got an update from the "yugabytedb" chart repository
9
 
          
10
$ helm search repo yugabytedb/yugabyte
11
 
          
12
NAME                   CHART VERSION    APP VERSION    DESCRIPTION                                       
13
yugabytedb/yugabyte    2.1.4            2.1.4.0-b5     YugabyteDB is the high-performance distributed ...



Create the yb-demo namespace.

Java
 




xxxxxxxxxx
1


 
1
$ kubectl create namespace yb-demo
2
 
          
3
namespace/yb-demo created



Next, we’ll install YugabyteDB in the yb-demo namespace by executing the following commands to specify settings for resource constrained environments.

Java
 




xxxxxxxxxx
1
12


 
1
$ helm install yb-demo -n yb-demo yugabytedb/yugabyte \
2
--set storage.master.count=1 \
3
--set storage.tserver.count=1 \
4
--set resource.master.requests.cpu=0.5 \
5
--set resource.master.requests.memory=1Gi \
6
--set resource.tserver.requests.cpu=0.5 \
7
--set resource.tserver.requests.memory=1Gi \
8
--set resource.master.limits.cpu=0.8 \
9
--set resource.master.limits.memory=1Gi \
10
--set resource.tserver.limits.cpu=0.8 \
11
--set resource.tserver.limits.memory=1Gi \
12
--timeout=15m



Depending on your resources, it may take some time to get everything installed, deployed, and configured. Once the command prompt returns with success, let’s verify that the YugabyteDB pods are running using the following command:

Java
 




xxxxxxxxxx
1


 
1
$ kubectl get pods --namespace yb-demo



To access the Yugabyte Admin UI run the following command to locate the External IP entry associated with yb-master-ui and port 7000.

Java
 




xxxxxxxxxx
1


 
1
$ kubectl get services --namespace yb-demo


Now, go to http://EXTERNAL_IP:7000. Replace EXTERNAL_IP with your own. You should see the following:

Bonus: Installing the Northwind Sample Database

If you’d like to install a sample database and you are coming from the Microsoft or SQL Server world, the Northwind database is a familiar one to install and get started with.

The following files that will be used to create and populate the example tables are already present on the YugabyteDB pods:

  • Northwind_ddl: Contains DDL statements to create tables and other database objects.
  • Northwind_data: Contains DML statements to load the sample data.

Connect to the YSQL shell by running the following commands:

Java
 




xxxxxxxxxx
1


 
1
$ kubectl exec -n yb-demo -it yb-tserver-0 /bin/bash
2
 
          
3
[root@yb-tserver-0 yugabyte]# /home/yugabyte/bin/ysqlsh -h yb-tserver-0.yb-tservers.yb-demo



Create the Northwind database and the tables by running the following commands from within the YSQL shell:

Java
 




xxxxxxxxxx
1


 
1
yugabyte=# CREATE DATABASE northwind;
2
CREATE DATABASE
3
yugabyte=# \c northwind
4
You are now connected to database "northwind" as user "yugabyte".
5
northwind=# \i share/northwind_ddl.sql
6
northwind=# \i share/northwind_data.sql



We can do a simple verification that the data has been inserted into the tables by running the following command:

Java
 




xxxxxxxxxx
1


 
1
northwind=# SELECT customer_id, company_name, contact_name FROM customers LIMIT 2;


Conclusion

That’s it, you now have YugabyteDB and the Northwind sample database running on an Azure Kubernetes cluster! At this point, you are ready to start exploring YSQL’s capabilities. We recommend starting with the YSQL docs and then reading up on the YugabyteDB’s architecture and design goals.

Topics:
azure, cloud native, cloud native and kubernetes, distributed sql, distributed sql databases, kubernetes, postgresql, yugabytedb

Published at DZone with permission of Jimmy Guerrero . See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}