Home
Softono
opensource-gslb

opensource-gslb

Open source Apache-2.0 Go
24
Stars
5
Forks
1
Issues
1
Watchers
7 years
Last Commit

About opensource-gslb

opensource-gslb is a DNS load balancer written in Go that distributes traffic across multiple backend servers based on domain name resolution. It runs as a custom DNS server configurable via a JSON file specifying domains, records, IP pools, TTL values, and an optional upstream relay server for resolving undefined domains. Key features include wildcard record support, allowing any subdomain to be matched against a defined record set. Specific records take precedence over wildcards. The default load balancing uses simple round-robin selection, but the strategy is pluggable, enabling developers to implement custom algorithms by providing a function that selects an IP from a given list. Health checking is configurable per record at both Layer 4 and Layer 7. Layer 4 checks verify TCP port availability at a configurable frequency. Layer 7 checks perform HTTP or HTTPS requests against a specified path and host, optionally skipping SSL verification, and validate the response against an expected status code. Configur

Platforms

Web Self-hosted

Languages

Go

Links

A DNS Load Balancer by golang

Run it

gtm --config config.json

Configuration

{
  "domains": [
    {
        "name" : "xip.io.",
        "records": [
          {
            "name": "abc",
            "ips": [
                {
                  "address": "10.193.190.181"
                },
                {
                  "address": "10.193.148.200"
                }
            ],
            "ttl" : 5
          },
          {
            "name": "*",
            "ips": [
                {
                  "address": "10.193.190.103"
                },
                {
                  "address": "10.193.148.251"
                }
            ],
            "ttl" : 10,
            "health_check" : {
              "type": "layer4",
              "port": 443,
              "frequency": "5s"
            }
          }
        ]
    },
    {
          "name" : "example.io.",
          "records" : [
            {
              "name": "*",
              "ips": [
                  {
                    "address": "10.0.5.4"
                  },
                  {
                    "address": "10.0.5.5"
                  }
              ],
              "ttl" : 5
            }
          ]
    }
  ],
  "port" : 5050,
  "relay_server" : "8.8.8.8:53"
}

Domain and records

  • It supports wild card records E.g.

    dig [anything].xip.io @localhost -p 5050

    will results either 10.193.190.103 or 10.193.148.251

  • It supports a specify record and will take precedence over
    E.g.

dig abc.xip.io @localhost -p 5050

will results either 10.193.190.181 or 10.193.148.200

Port

Port Number DNS server should listen on.

Relay Server

If the records/domains not defined in the configured domains, they will be resolved from the relay server

Plugin in your own Load Balancing logic

Currently, the load balancing strategy is extremely naive:

var simpleLoadBalancer gtm.LoadBalancing = func(ips []gtm.IP) string {
  //Simple Round Robin
  return ips[rand.Intn(len(ips))].Address
}

The load balancing logic is pluggable as long as developer implement another load balancer method func(ips[]gtm.IP) string

Layer4 Health Check

For each record, a layer 4 health check endpoint can be configured

"health_check" : {
  "type": "layer4",
  "port": 5000,
  "frequency": "5s"
}

Layer7 Health Check

For each record, you can configure a layer7 health check. Health check will do http/https check and match the http return code.

"records": [
  {
    "name": "api.test-gtm",
    "ips": [
        {
          "address": "10.193.190.103",
          "layer7_health_check_host": "simple-api.pks.nsx.shaozhenpcf.com"
        },
        {
          "address": "10.193.148.251",
          "layer7_health_check_host": "simple-api.pas.nsx-t.shaozhenpcf.com"
        }
    ],
    "ttl" : 5,
    "health_check" : {
      "type": "layer7",
      "https": true,
      "skip_ssl": true,
      "frequency": "5s",
      "path": "/whichcf",
      "http_status_code": 200
    }
  }
]