Skip to content

Commit

Permalink
Make it possible to specify the image
Browse files Browse the repository at this point in the history
  • Loading branch information
vitobotta committed Nov 13, 2021
1 parent b355398 commit 8d8bf7c
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 14 deletions.
21 changes: 18 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ This will install the `hetzner-k3s` executable in your PATH.
Alternatively, if you don't want to set up a Ruby runtime but have Docker installed, you can use a container. Run the following from inside the directory where you have the config file for the cluster (described in the next section):

```bash
docker run --rm -it -v ${PWD}:/cluster -v ${HOME}/.ssh:/tmp/.ssh vitobotta/hetzner-k3s:v0.4.6 create-cluster --config-file /cluster/test.yaml
docker run --rm -it -v ${PWD}:/cluster -v ${HOME}/.ssh:/tmp/.ssh vitobotta/hetzner-k3s:v0.4.7 create-cluster --config-file /cluster/test.yaml
```

Replace `test.yaml` with the name of your config file.
Expand Down Expand Up @@ -97,8 +97,20 @@ curl \
'https://api.hetzner.cloud/v1/server_types'
```

By default, the image in use is Ubuntu 20.04, but you can specify an image to use with the `image` config option. This makes it also possible
to use a snapshot that you have already created from and existing server (for example to preinstall some tools). If you want to use a custom
snapshot you'll need to specify the **ID** of the snapshot/image, not the description you gave when you created the template server. To find
the ID of your custom image/snapshot, run:

Note: the option `verify_host_key` is by default set to `false` to disable host key verification. This is because sometimes when creating new servers, Hetzner may assign IP addresses that were previously used by other servers you owned in the past. Therefore the host key verification would fail. If you set this option to `true` and this happens, the tool won't be able to continue creating the cluster until you resolve the issue with one of the suggestions it will give you.
```bash
curl \
-H "Authorization: Bearer $API_TOKEN" \
'https://api.hetzner.cloud/v1/images'
```

Note that if you use a custom image, the creation of the servers may take longer than when using the default image.

Also note: the option `verify_host_key` is by default set to `false` to disable host key verification. This is because sometimes when creating new servers, Hetzner may assign IP addresses that were previously used by other servers you owned in the past. Therefore the host key verification would fail. If you set this option to `true` and this happens, the tool won't be able to continue creating the cluster until you resolve the issue with one of the suggestions it will give you.

Finally, to create the cluster run:

Expand Down Expand Up @@ -242,7 +254,10 @@ I recommend that you create a separate Hetzner project for each cluster, because

## changelog

- 0.4.5
- 0.4.7
- Made it possible to specify a custom image/snapshot for the servers

- 0.4.6
- Added a check to abort gracefully when for some reason one or more servers are not created, for example due to temporary problems with the Hetzner API.

- 0.4.5
Expand Down
6 changes: 3 additions & 3 deletions bin/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ set -e

IMAGE="vitobotta/hetzner-k3s"

docker build -t ${IMAGE}:v0.4.6 \
docker build -t ${IMAGE}:v0.4.7 \
--platform=linux/amd64 \
--cache-from ${IMAGE}:v0.4.5 \
--cache-from ${IMAGE}:v0.4.6 \
--build-arg BUILDKIT_INLINE_CACHE=1 .

docker push vitobotta/hetzner-k3s:v0.4.6
docker push vitobotta/hetzner-k3s:v0.4.7
4 changes: 2 additions & 2 deletions lib/hetzner/infra/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def initialize(hetzner_client:, cluster_name:)
@cluster_name = cluster_name
end

def create(location:, instance_type:, instance_id:, firewall_id:, network_id:, ssh_key_id:, placement_group_id:)
def create(location:, instance_type:, instance_id:, firewall_id:, network_id:, ssh_key_id:, placement_group_id:, image:)
puts

server_name = "#{cluster_name}-#{instance_type}-#{instance_id}"
Expand All @@ -21,7 +21,7 @@ def create(location:, instance_type:, instance_id:, firewall_id:, network_id:, s
server_config = {
name: server_name,
location: location,
image: "ubuntu-20.04",
image: image,
firewalls: [
{ firewall: firewall_id }
],
Expand Down
15 changes: 10 additions & 5 deletions lib/hetzner/k3s/cluster.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ def create_resources
firewall_id: firewall_id,
network_id: network_id,
ssh_key_id: ssh_key_id,
placement_group_id: placement_group_id
placement_group_id: placement_group_id,
image: image
}
end

Expand All @@ -144,7 +145,8 @@ def create_resources
firewall_id: firewall_id,
network_id: network_id,
ssh_key_id: ssh_key_id,
placement_group_id: placement_group_id
placement_group_id: placement_group_id,
image: image
}
end
end
Expand All @@ -157,9 +159,8 @@ def create_resources

threads.each(&:join) unless threads.empty?

if server_configs.size != servers.size
puts "Something went wrong while creating some servers, please try again."
exit 1
while servers.size != server_configs.size
sleep 1
end

puts
Expand Down Expand Up @@ -656,4 +657,8 @@ def schedule_workloads_on_masters?
schedule_workloads_on_masters ? !!schedule_workloads_on_masters : false
end

def image
configuration.dig("image") || "ubuntu-20.04"
end

end
2 changes: 1 addition & 1 deletion lib/hetzner/k3s/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Hetzner
module K3s
VERSION = "0.4.6"
VERSION = "0.4.7"
end
end

0 comments on commit 8d8bf7c

Please sign in to comment.