You can add nodes to a node pool programmatically via the DigitalOcean API. For example, you can list the node pools in your cluster by sending a GET request to https://api.digitalocean.com/v2/kubernetes/clusters/<k8s-cluster-id>/node_pools
. Using cURL
it would look like:
$ curl -X GET -H "Content-Type: application/json" \
-H "Authorization: Bearer $DO_TOKEN" \
"https://api.digitalocean.com/v2/kubernetes/clusters/c801fb70-7086-4686-b4f0-95788435d032/node_pools" \
| jq .
{
"node_pools": [
{
"id": "c6561251-78c7-4824-830e-92610d1d7e5e",
"name": "example-cluster-01-default-pool",
"size": "s-1vcpu-2gb",
"count": 3,
"tags": [
"k8s",
"k8s:c801fb70-7086-4686-b4f0-95788435d032",
"k8s:worker"
],
"nodes": [
{
"id": "8d077fb6-8350-4564-936d-cfca4ceab9ee",
"name": "example-cluster-01-default-pool-yqdj",
"status": {
"state": "running"
},
"created_at": "2019-05-21T15:22:36Z",
"updated_at": "2019-05-21T15:26:02Z"
},
{
"id": "a35e9b2b-d0d5-4790-976f-0ceba17479e9",
"name": "example-cluster-01-default-pool-yqdr",
"status": {
"state": "running"
},
"created_at": "2019-05-21T15:22:36Z",
"updated_at": "2019-05-21T15:26:02Z"
},
{
"id": "cc32b6b5-5a05-49b1-b12e-8adb971ef3c9",
"name": "example-cluster-01-default-pool-yqdb",
"status": {
"state": "running"
},
"created_at": "2019-05-21T15:22:36Z",
"updated_at": "2019-05-21T15:26:02Z"
}
]
}
]
}
Now that we have the ID for the node pool, we can send a PUT request to https://api.digitalocean.com/v2/kubernetes/clusters/<k8s-cluster-id>/node_pools/<node-pool-id>
adding an additional node:
$ curl -X PUT -H "Content-Type: application/json" \
-H "Authorization: Bearer $DO_TOKEN" \
-d '{"name": "example-cluster-01-default-pool-yqdj","count": 4}' \
"https://api.digitalocean.com/v2/kubernetes/clusters/c801fb70-7086-4686-b4f0-95788435d032/node_pools/c6561251-78c7-4824-830e-92610d1d7e5e" \
| jq .
You can remove nodes using the same technique or delete a specific node if you want finer control.