|
1 | | -# nomad-hcloud-autoscaler |
| 1 | +# Hetzner Cloud Server Target Plugin |
2 | 2 |
|
3 | | -## Demo |
4 | | -Run `terraform apply` in [demo](demo/setup) folder to create: |
5 | | - - nomad server which runs services for: |
6 | | - - nomad-autoscaler |
7 | | - - prometheus |
8 | | - - redis |
| 3 | +The `hcloud-server` target plugin allows for the scaling of the Nomad cluster clients via manipulating [Hetzner Cloud Servers][hcloud_servers]. |
9 | 4 |
|
10 | | -Autoscaler scales hcloud nodes for redis. After successful run both Nomad and Consul are wide-world open and credentials for both you can find in terraform output |
| 5 | +## Agent Configuration Options |
11 | 6 |
|
| 7 | +To use the `hcloud-server` target plugin, the agent configuration needs to be populated with the appropriate target block. |
12 | 8 |
|
13 | | -## Configuration |
14 | | - |
15 | | -`config.hcl` |
16 | | -``` |
17 | | -template { |
18 | | - data = <<-EOF |
19 | | - nomad { |
20 | | - address = "http://{{env "attr.unique.network.ip-address" }}:4646" |
21 | | - } |
22 | | -
|
23 | | - telemetry { |
24 | | - prometheus_metrics = true |
25 | | - disable_hostname = true |
26 | | - } |
27 | | -
|
28 | | - apm "prometheus" { |
29 | | - driver = "prometheus" |
30 | | - config = { |
31 | | - address = "http://{{ range service "prometheus" }}{{ .Address }}:{{ .Port }}{{ end }}" |
32 | | - } |
33 | | - } |
34 | | -
|
35 | | - strategy "target-value" { |
36 | | - driver = "target-value" |
37 | | - |
38 | | - } |
39 | | -
|
40 | | - target "hcloud-server" { |
41 | | - driver = "hcloud-server" |
42 | | - config = { |
43 | | - hcloud_token = "YOUR_HCLOUD_TOKEN" |
44 | | - } |
45 | | - } |
46 | | - |
47 | | - EOF |
48 | | -
|
49 | | - destination = "${NOMAD_TASK_DIR}/config.hcl" |
50 | | - change_mode = "signal" |
51 | | - change_signal = "SIGHUP" |
| 9 | +```hcl |
| 10 | +target "hcloud-server" { |
| 11 | + driver = "hcloud-server" |
| 12 | + config = { |
| 13 | + hcloud_token = "YOUR_HCLOUD_TOKEN" |
| 14 | + } |
52 | 15 | } |
53 | 16 | ``` |
54 | 17 |
|
55 | | -`policy` |
| 18 | +- `hcloud_token` `(string: required)` - The [Hetzner Cloud token][hcloud_token] used to authenticate to connect to and where resources should be managed. |
| 19 | + |
| 20 | +- `hcloud_random_suffix_len` `(string: "10")` - Random Server name suffix length |
| 21 | + |
| 22 | +- `hcloud_retry_interval` `(string: "1m")` - Hetzner Cloud API retry interval |
| 23 | + |
| 24 | +- `hcloud_retry_limit` `(string: "5")` - Hetzner Cloud API retry limit |
56 | 25 |
|
| 26 | +- `hcloud_items_per_page` `(string: "50")` - Hetzner Cloud API request page size |
| 27 | + |
| 28 | +- `hcloud_group_id_label_selector` `(string: "group-id")` - Server group id label selector |
| 29 | + |
| 30 | +- `hcloud_node_attr_id` `(string: "unique.hostname")` - Nomad Node attribute id |
| 31 | + |
| 32 | +### Nomad ACL |
| 33 | + |
| 34 | +When using a Nomad cluster with ACLs enabled, the plugin will require an ACL token which provides the following permissions: |
| 35 | + |
| 36 | +```hcl |
| 37 | +node { |
| 38 | + policy = "write" |
| 39 | +} |
57 | 40 | ``` |
58 | | -template { |
59 | | - data = <<-EOF |
60 | | - scaling "cluster_class-batch" { |
61 | | - enabled = true |
62 | | - min = 1 |
63 | | - max = 2 |
64 | | -
|
65 | | - policy { |
66 | | - cooldown = "5m" |
67 | | - evaluation_interval = "5m" |
68 | | -
|
69 | | - check "test-scale" { |
70 | | - source = "prometheus" |
71 | | - query = "YOUR_DESIRED_METRIC" |
72 | | -
|
73 | | - strategy "target-value" { |
74 | | - target = 2 |
75 | | - } |
76 | | - } |
77 | | -
|
78 | | - target "hcloud-server" { |
79 | | - // datacenter = "XXX" |
80 | | - node_class = "XXX" |
81 | | - dry-run = "false" |
82 | | - // node_selector_strategy = "newest_create_index" |
83 | | - hcloud_location = "XXX" |
84 | | - hcloud_image = "XXX" |
85 | | - hcloud_user_data = "" |
86 | | - hcloud_ssh_keys = "XXX" |
87 | | - hcloud_server_type = "cx11" |
88 | | - hcloud_group_id = "XXX" |
89 | | - hcloud_labels = "XXX_node=true" |
90 | | - hcloud_networks = "XXX" |
91 | | - } |
92 | | - } |
93 | | - } |
94 | | - EOF |
95 | | - destination = "${NOMAD_TASK_DIR}/policies/hcloud.hcl" |
96 | | - change_mode = "signal" |
97 | | - change_signal = "SIGHUP" |
| 41 | + |
| 42 | +## Policy Configuration Options |
| 43 | + |
| 44 | +```hcl |
| 45 | +check "hashistack-allocated-cpu" { |
| 46 | + # ... |
| 47 | + target "hcloud-server" { |
| 48 | + datacenter = "XXX" |
| 49 | + node_class = "XXX" |
| 50 | + node_drain_deadline = "5m" |
| 51 | + node_purge = "true" |
| 52 | + node_selector_strategy = "newest_create_index" |
| 53 | + hcloud_location = "XXX" |
| 54 | + hcloud_image = "XXX" |
| 55 | + hcloud_user_data = "#cloud-config\npackages:\n - jq" |
| 56 | + hcloud_b64_user_data_encoded = "false" |
| 57 | + hcloud_ssh_keys = "XXX" |
| 58 | + hcloud_server_type = "cx11" |
| 59 | + hcloud_group_id = "XXX" |
| 60 | + hcloud_labels = "XXX_node=true" |
| 61 | + hcloud_networks = "XXX" |
| 62 | + } |
| 63 | + # ... |
98 | 64 | } |
99 | 65 | ``` |
| 66 | + |
| 67 | +- `hcloud_location` `(string: "")` - ID or name of [Location][hcloud_location] to create Server in (must not be used together with `hcloud_datacenter`). |
| 68 | + |
| 69 | +- `hcloud_datacenter` `(string: "")` - ID or name of [Datacenter][hcloud_datacenter] to create Server in (must not be used together with `hcloud_location`). |
| 70 | + |
| 71 | +- `hcloud_firewalls` `(string: "")` - Comma-separated list of [Firewall][hcloud_firewall] IDs |
| 72 | + |
| 73 | +- `hcloud_placement_group` `(string: "")` - [Placement Group][hcloud_placement_group] ID |
| 74 | + |
| 75 | +- `hcloud_image` `(string: required)` - ID or name of the [Image][hcloud_image] the Server is created from. |
| 76 | + |
| 77 | +- `hcloud_group_id` `(string: required)` - Server group name used for filtering targeted HCloud hosts. `group-id` label is attached to a server during creation. |
| 78 | + |
| 79 | +- `hcloud_user_data` `(string: required)` - [Cloud-Init][cloud_init] user data to use during Server creation. This field is limited to 32KiB. |
| 80 | + |
| 81 | +- `hcloud_b64_user_data_encoded` `(string: "false")` - Identifies if `hcloud_user_data` is base64 encoded or not. |
| 82 | + |
| 83 | +- `hcloud_ssh_keys` `(string: required)` - Comma-separated IDs or names of SSH keys which should be injected into the server at creation time. |
| 84 | + |
| 85 | +- `hcloud_labels` `(string: "")` - User-defined labels (key-value pairs) string in a format `key1=value1,key2=value2,...,keyN=valueN`. |
| 86 | + |
| 87 | +- `hcloud_networks` `(string: "")` - [Network][hcloud_networks] IDs which should be attached to the server private network interface at the creation time. |
| 88 | + |
| 89 | +- `datacenter` `(string: "")` - The Nomad client [datacenter][nomad_datacenter] identifier used to group nodes into a pool of resource. |
| 90 | + |
| 91 | +- `node_class` `(string: "")` - The Nomad [client node class][nomad_node_class] identifier used to group nodes into a pool of resource. |
| 92 | + |
| 93 | +- `node_drain_deadline` `(duration: "15m")` The Nomad [drain deadline][nomad_node_drain_deadline] to use when performing node draining actions. |
| 94 | + |
| 95 | +- `node_drain_ignore_system_jobs` `(bool: "false")` A boolean flag used to control if system jobs should be stopped when performing node draining actions. |
| 96 | + |
| 97 | +- `node_purge` `(bool: "false")` A boolean flag to determine whether Nomad clients should be [purged][nomad_node_purge] when performing scale in actions. |
| 98 | + |
| 99 | +- `node_selector_strategy` `(string: "least_busy")` The strategy to use when selecting nodes for termination. Refer to the [node selector strategy][node_selector_strategy] documentation for more information. |
| 100 | + |
| 101 | +[hcloud_servers]: https://docs.hetzner.com/cloud/servers |
| 102 | +[hcloud_datacenter]: https://www.hetzner.com/unternehmen/rechenzentrum |
| 103 | +[hcloud_token]: https://docs.hetzner.com/dns-console/dns/general/api-access-token/ |
| 104 | +[hcloud_location]: https://docs.hetzner.com/cloud/general/locations/ |
| 105 | +[hcloud_placement_group]: https://docs.hetzner.com/cloud/placement-groups/overview/ |
| 106 | +[hcloud_image]: https://docs.hetzner.com/robot/dedicated-server/operating-systems/standard-images/ |
| 107 | +[hcloud_networks]: https://docs.hetzner.com/cloud/networks/overview |
| 108 | +[hcloud_firewall]: https://docs.hetzner.com/robot/dedicated-server/firewall/ |
| 109 | +[cloud_init]: https://cloudinit.readthedocs.io/en/latest/ |
| 110 | +[nomad_datacenter]: /docs/configuration#datacenter |
| 111 | +[nomad_node_class]: /docs/configuration/client#node_class |
| 112 | +[nomad_node_drain_deadline]: /api-docs/nodes#deadline |
| 113 | +[nomad_node_purge]: /api-docs/nodes#purge-node |
| 114 | +[node_selector_strategy]: /tools/autoscaling/internals/node-selector-strategy |
| 115 | + |
| 116 | +## Demo |
| 117 | +Run `terraform apply` in [demo](demo/setup) folder to create: |
| 118 | + - nomad server which runs services for: |
| 119 | + - nomad-autoscaler |
| 120 | + - prometheus |
| 121 | + - redis |
| 122 | + |
| 123 | +Autoscaler scales hcloud nodes for redis. After successful run both Nomad and Consul are wide-world open and credentials for both you can find in terraform output |
0 commit comments