Skip to content
Visit Spectrum on GitHub
Set theme to dark (⇧+D)

Cloudflare Load Balancer

You can configure Spectrum and Cloudflare's Load Balancing to provide TCP healthchecks, failover, and traffic steering to bring resiliency to your Spectrum Applications. However, to prevent issues with DNS resolution for a Spectrum application, do not use the same Spectrum hostname as a current Load Balancing hostname.

TCP health checks

Cloudflare's Load Balancer can be configured to probe any TCP port for an accepted connection. This is in addition to HTTP and HTTPS probing capabilities.

Health Checks are optional within a Load Balancer. However, without one the load balancer will distribute traffic to all the origins in the first pool. With the Health Check enabled, hosts that have gone into an error state will not receive traffic maintaining uptime. This allows you to enable intelligent failover within a pool of hosts or amongst multiple pools.

The below image will configure a TCP health check for an application running on port 2408 with a refresh rate every 30 seconds. This can be configured through the dashboard or through Cloudflare's API.

Dashboard Example:

Health Check UI

API Example:

curl '{ORG_ID}/load_balancers/monitors'  \-H 'Content-Type: application/json' \-H 'X-Auth-Email:' \-H 'X-Auth-Key: 00000000000' \-X POST --data '{"description":"Spectrum Health Check","type":"tcp","port":2048,"interval":30,"retries":2,"timeout":5,"method":"connection_established"}'
{  "description": "Spectrum Health Check",  "type": "tcp",  "port": 2048,  "interval": 30,  "retries": 2,  "timeout": 5,  "method": "connection_established",}

Below is the procedure to enable a Cloudflare Load Balancer with Spectrum using the dashboard.


Origin Weights allow you to have origins that do not have the same capacity or if you want to split traffic amongst hosts for any other reason.

Weight is configured within a load balancer pool will be honored with load balancing through Spectrum. If configured, Cloudflare will distribute traffic amongst the available origins within a pool according to the relative weights assigned to each origin.

Steering modes

All steering modes are available for transport load balancing through Spectrum:

Load balancing rules

At the moment, you cannot use load balancing custom rules with Cloudflare Spectrum.


Step 1: Create a Load Balancer

You will need to create a Load Balancer on your Cloudflare managed zone. You can follow instructions on how to do so by following this tutorial.

Step 2: Create the Spectrum Application

Example using the Dashboard:

Navigate to the Spectrum tab in the dashboard and select the Add an Application button. Under the Origin section, select the Load Balancer radio button and select your new load balancer:

Spectrum Dashboard Configuration

Example Curl using the API:

curl -X POST '{ZONE_ID}/spectrum/apps' \-H "Content-Type: application/json" \-H "X-Auth-Email: email" \-H "X-Auth-Key: key" \--data '{"dns":{"type":"CNAME","name":""},"ip_firewall":false,"protocol":"tcp/22","proxy_protocol":false,"tls":"off","origin_dns": {"name": "", "ttl": 1200}, "origin_port": 22}'

Example Data:

{    "dns": {        "type": "CNAME",        "name": ""    },    "ip_firewall": false,    "protocol": "tcp/22",    "proxy_protocol": false,    "tls": "off",    "origin_dns": {        "name": "",        "ttl": 1200    },    "origin_port": 22}