3

Using Azure Load Balancer With CockroachDB

 2 years ago
source link: https://dzone.com/articles/using-azure-load-balancer-with-cockroachdb
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Motivation

The purpose of this tutorial is to provide step-by-step instructions in getting an Azure Load Balancer up quickly. Our docs do a great job at covering the CockroachDB portion but the granular steps to get ALB up are missing. Since this is my first foray into managed load balancers, I decided to do the hard work.

High-Level Steps

  • Provision a cluster in Azure
  • Provision a load balancer
  • Test connectivity
  • Clean up

Step by Step Instructions

This article assumes you've set up a Resource Group and a Virtual Network associated with it in your Azure subscription. Following this document will walk you through setting up a CockroachDB cluster. When you have these prerequisites in place, we can continue with setting up a load balancer.

Search for Load Balancer in the Azure Console

Setting up Azure load balancer with CockroachDB: Step - 1

Click Create.

Fill Out Create Load Balancer Modal

Setting up Azure load balancer with CockroachDB: Step - 2

Fill out the Frontend IP modal:

  • Add a frontend IP configuration.
  • Fill out the Public IP address.

Setting up Azure load balancer with CockroachDB: Step - 3

Add the front-end IP address.

Setting up Azure load balancer with CockroachDB: Step - 4

Click Add.

Setting up Azure load balancer with CockroachDB: Step - 5

Add Backend Pools

Add a backend pool.

Setting up Azure load balancer with CockroachDB: Step - 6

Click Add.

Setting up Azure load balancer with CockroachDB: Step - 7

Create Inbound Rules

Setting up Azure load balancer with CockroachDB: Step - 8

  • Add a load balancing rule.
  • Add a health probe.

Be careful with choosing the right port for the health probe. My cluster exposes the health endpoint at port 26258 but I mistakenly assumed it was 8080, which is the default for CockroachDB. This can trip you up. Typically the health endpoint is exposed at the following url.

Setting up Azure load balancer with CockroachDB: Step - 9

Load balancing rule:

Setting up Azure load balancer with CockroachDB: Step - 10

Click Add.

Setting up Azure load balancer with CockroachDB: Step - 11

Click Next to skip Outbound Rules.

Click Next to Add Tags

This step is optional depending on your organization. I prefer to tag my cloud resources.

Setting up Azure load balancer with CockroachDB: Step - 12

Review and Create

Setting up Azure load balancer with CockroachDB: Step - 13

Optionally, download the template for automation.

Setting up Azure load balancer with CockroachDB: Step - 14

You have a choice to deploy from this same template in this screen or hit the breadcrumb menu up top to go back to the previous screen and deploy the load balancer that way. Both steps will have the same result.

Setting up Azure load balancer with CockroachDB: Step - 15

Hit Deploy!

Setting up Azure load balancer with CockroachDB: Step - 16

Setting up Azure load balancer with CockroachDB: Step - 17

Click Create.

Once it completes, find the Load Balancer in the console and copy the public IP:

Setting up Azure load balancer with CockroachDB: Step - 18

Test Connectivity

Now that we're finished deploying a load balancer, we can test the connectivity to the cluster via LB. Copy the public IP to the clipboard.

Connect to the cluster from your client machine:

cockroach sql --insecure --host=<Your LB public IP>

In the case of secure clusters, you will need to pass --certs-dir flag pointing to the cluster certs you used to set up the cluster. You also need to make sure to include the load balancer public IP when you create node certs. Otherwise, you will get the following error:

cockroach sql --certs-dir=certs --host=20.97.200.152
#
ERROR: x509: certificate is valid for 10.1.0.4, 10.1.0.5, 10.1.0.6, 20.186.27.148, 20.186.26.192, 20.186.27.127, not 20.97.200.152
Failed running "sql"

Where 20.97.200.152 is the public IP of the LB.

Assuming everything is configured correctly, you should see a similar output in your terminal:

cockroach sql --insecure --host=20.97.200.152
#
# Welcome to the CockroachDB SQL shell.
# All statements must be terminated by a semicolon.
# To exit, type: \q.
#
# Server version: CockroachDB CCL v21.2.5 (x86_64-unknown-linux-gnu, built 2022/02/07 21:01:07, go1.16.6) (same version as client)
#

Now in the console, we can issue commands to see which node we're connected to:

[email protected]:26257/defaultdb> select crdb_internal.node_id();
  crdb_internal.node_id
-------------------------
                      1

Let's exit out and connect again. Based on your set up you may have identical or different results. It may coincidentally point you to the same node, in which case exit out and try again.

[email protected]:26257/defaultdb> select crdb_internal.node_id();
  crdb_internal.node_id
-------------------------
                      3

This time we connected to node 3 instead. Having a managed load balancer has its advantages over managing a service like HAProxy manually. For once, you can configure zonal redundancy for the frontend IP and manage the service natively instead of Linux process, i.e. haproxy -f haproxy.cfg &.

That's it for today, hope you found this tutorial useful.


Recommend

  • 52

    The Network Load Balancer is designed to handle tens of millions of requests per sec...

  • 30

    Load Balancers plays a key role in Web Architecture. They allow distributing load among a set of backends. This makes services more scalable. Als...

  • 20

    Running Lambda Function behind an Application Load BalancerJuly 13, 2019When talking about APIs on Lambda Function, Api Gateway is the most common subject. AWS did a pretty good job providing a service to run code (Lambda) ext...

  • 17
    • blog.deleu.dev 3 years ago
    • Cache

    One Load Balancer to rule them all

    One Load Balancer to rule them allJuly 12, 2019If you read my introduction, you know I’m a cheap person. A few months ago I worked on a project that had about 10 microservices....

  • 11
    • www.volterra.io 3 years ago
    • Cache

    Multi-Cluster Load Balancer & API Gateway

    Multi-Cluster Load Balancer & API Gateway This website stores cookies on your computer. These cookies are used to collect information about how you interact with our website and allow us to remember you. We use this i...

  • 11
    • fuzzyblog.io 3 years ago
    • Cache

    A Poor Man's Load Balancer

    A Poor Man's Load Balancer Nov 28, 2016 So I've spent the last few days dealing with proxy servers and trying to get a group of AWS instances, all running squid, to hide behind a load balancer. And, alas, thi...

  • 10
    • azpodcast.azurewebsites.net 3 years ago
    • Cache

    Episode 368 - Azure Load Balancer

    Related postsEpisode 248 - Updates from Ignite 2018A whole bunch of Azure updates were announced at Ignite so Cynthia, Cale and Sujit t...

  • 5
    • www.howtoforge.com 2 years ago
    • Cache

    How to create a Load Balancer in Azure Cloud

    How to create a Load Balancer in Azure Cloud A Load Balancer is used to evenly distribute the load on the backend servers. It acts as the single point of contact for clients requesting it. It operates at a Transport Layer of the Ope...

  • 2

    Using Pipy as software load balancer Load balancing is a commonly used technique which refers to the process of distributing network traffic across multiple application instances and/or servers to optimize resource utilization, maximi...

  • 6

    Using Nginx like an AWS load balancer in local dev Sep 30, 2020 A typical production web application is set up behind a load balancer, with the SSL connection ter...

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK