Created
January 20, 2021 19:10
-
-
Save elhardoum/a02174c2dff29bb654bfc3471d6c751c to your computer and use it in GitHub Desktop.
Automatically add servers to your Linode nodebalancer. It's painful to do it manually when you have dozens of servers to add
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Please change your nodebalancer configuration in `payload` line 6, and clusters configurations | |
* in lines 13 and 19 | |
* | |
* This must be run within cloud.linode.com/ dashboard, ideally via DevTools > Console (or snippets) | |
*/ | |
const payload = { "protocol": "tcp", "proxy_protocol": "none", "algorithm": "source", "stickiness": "table", "check": "none", "check_interval": 5, "check_timeout": 3, "check_attempts": 2, "port": 443, "check_passive": true, "cipher_suite": "recommended", "nodes": [] } | |
, ips = [] // a list of your IP addresses | |
, promises = [] | |
, balancer_id = 115029 // you can find this in the network tab (XHR), try adding a new server to your load balancer, monitor the requests | |
, config_id = 142920 // same comment as above | |
for ( let i=0; i<ips.length; i++ ) { | |
payload.nodes.push({ label: `idr${i+1}`, address: ips[i], port: 443, weight: 100, mode: 'accept' }) | |
promises.push(fetch(`https://cloud.linode.com/api/v4/nodebalancers/${balancer_id}/configs/${config_id}/nodes`, { | |
"headers": { | |
"authorization": localStorage.getItem('authentication/token'), | |
"content-type": "application/json;charset=UTF-8", | |
}, | |
"body": JSON.stringify({ label: `idr${i+1}`, address: `${ips[i]}:443`, port: 443, weight: 100, mode: 'accept' }), | |
"method": "POST", | |
})) | |
} | |
await Promise.all(promises) | |
await fetch(`https://cloud.linode.com/api/v4/nodebalancers/${balancer_id}/configs/${config_id}`, { | |
"headers": { | |
"authorization": localStorage.getItem('authentication/token'), | |
"content-type": "application/json;charset=UTF-8", | |
}, | |
"body": JSON.stringify(payload), | |
"method": "PUT", | |
}).then(r => r.json()).then(console.log) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment