From 2953386f8baeadc7c4c892fd984d004da2f42b6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20T=C3=B6lle?= Date: Mon, 28 Oct 2024 14:22:25 +0100 Subject: [PATCH] chore(hetzner): setup kubernetes-dev-setup --- .../cloudprovider/hetzner/dev/.gitignore | 5 + .../hetzner/dev/.terraform.lock.hcl | 114 ++++++++++++++++++ .../cloudprovider/hetzner/dev/Makefile | 29 +++++ .../cloudprovider/hetzner/dev/main.tf | 8 ++ .../cloudprovider/hetzner/dev/variables.tf | 10 ++ .../hetzner/examples/cloud-init.sh | 8 ++ .../hetzner/examples/kustomization.yaml | 12 ++ .../cloudprovider/hetzner/skaffold.yaml | 20 +++ 8 files changed, 206 insertions(+) create mode 100644 cluster-autoscaler/cloudprovider/hetzner/dev/.gitignore create mode 100644 cluster-autoscaler/cloudprovider/hetzner/dev/.terraform.lock.hcl create mode 100644 cluster-autoscaler/cloudprovider/hetzner/dev/Makefile create mode 100644 cluster-autoscaler/cloudprovider/hetzner/dev/main.tf create mode 100644 cluster-autoscaler/cloudprovider/hetzner/dev/variables.tf create mode 100644 cluster-autoscaler/cloudprovider/hetzner/examples/cloud-init.sh create mode 100644 cluster-autoscaler/cloudprovider/hetzner/examples/kustomization.yaml create mode 100644 cluster-autoscaler/cloudprovider/hetzner/skaffold.yaml diff --git a/cluster-autoscaler/cloudprovider/hetzner/dev/.gitignore b/cluster-autoscaler/cloudprovider/hetzner/dev/.gitignore new file mode 100644 index 000000000000..fa77144e73fe --- /dev/null +++ b/cluster-autoscaler/cloudprovider/hetzner/dev/.gitignore @@ -0,0 +1,5 @@ +.terraform/ +terraform.tfstate* +*.auto.tfvars + +files/ diff --git a/cluster-autoscaler/cloudprovider/hetzner/dev/.terraform.lock.hcl b/cluster-autoscaler/cloudprovider/hetzner/dev/.terraform.lock.hcl new file mode 100644 index 000000000000..f3c6412d3cd4 --- /dev/null +++ b/cluster-autoscaler/cloudprovider/hetzner/dev/.terraform.lock.hcl @@ -0,0 +1,114 @@ +# This file is maintained automatically by "tofu init". +# Manual edits may be lost in future updates. + +provider "registry.opentofu.org/hashicorp/helm" { + version = "2.16.1" + constraints = ">= 2.14.1, < 3.0.0" + hashes = [ + "h1:OAMufKLYnPEyJMNMaOFYQys3HdXtFdaT7kEaWmaINTI=", + "zh:1c820d7997377c80c320b3bb4f257258af6c499bf2f2082a87975854b156b82b", + "zh:223dc3ba691a03eeb32d14160b3c6adc77d55a767274c728250cd4f1d4238a2a", + "zh:332095747133eb558da1455056f993314b16346d46065967ffe5f7b243614591", + "zh:46155a04e08e9790e22cb7b70d83cdf908e36121597c801a9300f8c100f1ad01", + "zh:51974f6ceb6b4c2aa575384a0cc1fbad22b8b868558e969a196575d43e9d0198", + "zh:7da302779eb39e63a62a0928e391852054ad83eb2025c190475c94a5afc77d29", + "zh:947bbf2a4d8461ec4a544ef7b76f45815602563123987a63dce843258440aa24", + "zh:b84a6658447bbd46daff26010771f0e2168423f0f7f1c1bc2b4ba53f9e891263", + "zh:dd21fdb13d85467b848682c63f440974cef99472d988794f019630f20ac3d2e6", + "zh:e0f77d2f7cf84d6c0d7f30f6cdc325c319ff4eadd525c6fb6979da62e5ff843d", + ] +} + +provider "registry.opentofu.org/hashicorp/kubernetes" { + version = "2.33.0" + constraints = ">= 2.31.0, < 3.0.0" + hashes = [ + "h1:bKw7j/Unbym/WPdFiKMZ0i/84SpPe8g2cgrzM7TkGaQ=", + "zh:00aed83f28880460431f70e5a057c9324d1228b3f76e6554199700632ca62361", + "zh:4aac46187fd23bdabd801290070fa718609a2064ed5c876c4ab61fdf6e46ea04", + "zh:676dd70c2ff3df25a962bae4b11a2896d4313b0fd39132ec78ae3418bb1b2ef5", + "zh:6a01808157d2c9b415b49ea1d294cd19262a89b3b02e0de8d1db6cdc393dffa9", + "zh:941a0ef4b851ad37cff9ef9d38849529b5fb0c6b3ad149a6c2457d50b7964adf", + "zh:9a7b0ec7d84a481d9c7544056e0639d240e1373a1d61d4aebce049cc9673a6a6", + "zh:a6c68f47f72089f426b9a9040cc8a9fcb98d362b5b35d26028781f9fec3f0293", + "zh:a6ccb8f33dd52ceaca754cb51aea667fc9a8e3bfd5a192002005b7cfece65ee5", + "zh:e63a6fb4a72a0634f2fb0c261d5dea0182f13b5f9f0cd1560344602cc7482b68", + "zh:f0b79ba3c5f28b688b802ef0f052b6b4f99aa45a70e8d4efe21fd824f7a69c6c", + ] +} + +provider "registry.opentofu.org/hashicorp/local" { + version = "2.5.2" + constraints = ">= 2.5.1, < 3.0.0" + hashes = [ + "h1:6lS+5A/4WFAqY3/RHWFRBSiFVLPRjvLaUgxPQvjXLHU=", + "zh:25b95b76ceaa62b5c95f6de2fa6e6242edbf51e7fc6c057b7f7101aa4081f64f", + "zh:3c974fdf6b42ca6f93309cf50951f345bfc5726ec6013b8832bcd3be0eb3429e", + "zh:5de843bf6d903f5cca97ce1061e2e06b6441985c68d013eabd738a9e4b828278", + "zh:86beead37c7b4f149a54d2ae633c99ff92159c748acea93ff0f3603d6b4c9f4f", + "zh:8e52e81d3dc50c3f79305d257da7fde7af634fed65e6ab5b8e214166784a720e", + "zh:9882f444c087c69559873b2d72eec406a40ede21acb5ac334d6563bf3a2387df", + "zh:a4484193d110da4a06c7bffc44cc6b61d3b5e881cd51df2a83fdda1a36ea25d2", + "zh:a53342426d173e29d8ee3106cb68abecdf4be301a3f6589e4e8d42015befa7da", + "zh:d25ef2aef6a9004363fc6db80305d30673fc1f7dd0b980d41d863b12dacd382a", + "zh:fa2d522fb323e2121f65b79709fd596514b293d816a1d969af8f72d108888e4c", + ] +} + +provider "registry.opentofu.org/hashicorp/null" { + version = "3.2.3" + constraints = ">= 3.2.2, < 4.0.0" + hashes = [ + "h1:LF8arSzHfhbyQSFtTMTYEqCM34klzrbAQBJMHYCs9d8=", + "zh:1d57d25084effd3fdfd902eca00020b34b1fb020253b84d7dd471301606015ac", + "zh:65b7f9799b88464d9c2ec529713b7f52ea744275b61a8dc86cdedab1b2dcb933", + "zh:80d3e9c95b7b4ae7c54005cd127cae82e5c53d2b7023ef24c147337bac9dadd9", + "zh:841b60c07683e4bf456799ccd718896fdafdcc2c49252ae09967f2e74d8c8a03", + "zh:8fa1c592a9c78222e35713c6edb3f1f818a4c6f3524a30a209f0a7e919827b68", + "zh:bb795cc1429e09466840c09d39a28edf1db5070b1ec76822fc1173906a264572", + "zh:da1784818a89bea29dfe660632f0060a7a843e4e564d74435fbeca002b0f7d2a", + "zh:f409bf21b1cdaa6dac47cd79806f3d93f67e9507fe4dbf33b0165335f53bc2e1", + "zh:fbea7a1ff84b430ba9594698e93196d81d03e4036de3d1cafccb2a96d5b38581", + "zh:fbf0c84663a7e85881388d7d71ac862184f05fbf2d17ecf76bc5d3d7503ea260", + ] +} + +provider "registry.opentofu.org/hashicorp/tls" { + version = "4.0.6" + constraints = ">= 4.0.5, < 5.0.0" + hashes = [ + "h1:EJoUGDo7L52Iu22cA1KCndJ9B1Rrfd75wyZzsScEnc0=", + "zh:4b53b372767e5068d9bbfc89199201c1ae4283dde2f0c301974f8abb4215791f", + "zh:5b4c308bd074c6d0bd560220e6ee10a9859ca9a1f29a59367b0477a740ff265e", + "zh:674dd6bc85597677e160ee601d88b21c5a974759a658769812d2904bd94bc042", + "zh:6ccc1c448349b56677ba66112aec7e0a58eb827f66209ca5f4077b81cce240fb", + "zh:8aa6e13a5d722b74230937ea21e8b4994e53340d95b5691cf6cf3518b9f38e6e", + "zh:8b27e55e4c7fa887774860113b95c8f7f68804b002fa47f0eb8e3a485997287e", + "zh:a430b5a3e8753d8f61784de49e538ac4abed19fb665fccd8a10b55402fe9f076", + "zh:b07c978c335ae9fc12f9c221629610775e4ae36691ed4e7ba258d275dd58a243", + "zh:bbec8cb1efc84ee3026c793956a4a4cd0ece20b89d2d4f7d954c68e7f6d596d0", + "zh:e684e247424188dc3b500a543b1a8046d1c0ec08c2a90aedca0c4f6bb56bedbd", + ] +} + +provider "registry.opentofu.org/hetznercloud/hcloud" { + version = "1.48.1" + constraints = ">= 1.48.0, < 2.0.0" + hashes = [ + "h1:fa9fxdSV9DG+HDcXyRbcGfb6Dk94SBP3TamHb1yOYiI=", + "zh:086cce10cb005f25f85183c59e639d6675e91e919934c80f660ca1cc4b9bc09b", + "zh:111d185707168b90c7ed3d245b522b2bd508f0bd4275496a1acdc9c0adaa85f2", + "zh:1acba3f30150282d283c46cd7ce25e9afb8b027fd2f594d41de9131d25a42b27", + "zh:1f8858aa81f93d52550502a11c7ea4e9370316ab098f6b75a09ffe75da6129ee", + "zh:20e01e6e6f99f57b3c1ef2a9de5d617c0139d3f3934eeb5e6c5976ae8b831a48", + "zh:2a8489a586a7bdadc42bbc9e3cb7b9deaefdf8020e3f2caba2678877d5d64d52", + "zh:31d8017529b0429bc9e873ec5d358ab9b75af2ba0ae24f21abcd4d09f36b7ee9", + "zh:407b4d7f1407e7e4a51b6f4dcdb0c7fbf81f2f1e25a7275f34054009419125a2", + "zh:42cf7cf867d199054713d4e6060e4b578eff16f0f537e9aaa5fd990c3eab8bc6", + "zh:460ac856ff952c5d41525949b93cfb7ee642f900594eff965494f11999d7496b", + "zh:d09e527d23f62564c82bc24e286cf2cb8cb0ed6cdc6f4c66adf2145cfa62adac", + "zh:d465356710444ac70dea4883252efc429b73e79fc6dc94f075662b838476680e", + "zh:d476c8eca307e30a20eed54c0735b062a6f3066b4ac63eebecd38ab8f40c16f4", + "zh:e0e9b2f6d5e28dbd01fa1ec3147aa88062d6223c5146532a3dcd1d3bb827e1e9", + ] +} diff --git a/cluster-autoscaler/cloudprovider/hetzner/dev/Makefile b/cluster-autoscaler/cloudprovider/hetzner/dev/Makefile new file mode 100644 index 000000000000..aee0a4cbed0d --- /dev/null +++ b/cluster-autoscaler/cloudprovider/hetzner/dev/Makefile @@ -0,0 +1,29 @@ +SHELL = bash + +ENV ?= dev +K3S_CHANNEL ?= stable + +env.auto.tfvars: + @echo 'name = "$(ENV)"' > "$@" + @echo 'hcloud_token = "$(HCLOUD_TOKEN)"' >> "$@" + @echo 'k3s_channel = "$(K3S_CHANNEL)"' >> "$@" + +.terraform: + tofu init + +validate: .terraform + tofu validate + +up: .terraform env.auto.tfvars + tofu apply -auto-approve + $(MAKE) port-forward + +down: .terraform env.auto.tfvars + files/registry-port-forward.sh down + tofu destroy -auto-approve + +port-forward: + source files/env.sh && files/registry-port-forward.sh up + +clean: + rm -Rf files/ .terraform/ terraform.tfstate* env.auto.tfvars diff --git a/cluster-autoscaler/cloudprovider/hetzner/dev/main.tf b/cluster-autoscaler/cloudprovider/hetzner/dev/main.tf new file mode 100644 index 000000000000..01b097f1ab4c --- /dev/null +++ b/cluster-autoscaler/cloudprovider/hetzner/dev/main.tf @@ -0,0 +1,8 @@ +module "dev" { + source = "github.com/hetznercloud/kubernetes-dev-env?ref=v0.6.0" # x-release-please-version + + name = "cas-${replace(var.name, "/[^a-zA-Z0-9-_]/", "-")}" + hcloud_token = var.hcloud_token + + k3s_channel = var.k3s_channel +} diff --git a/cluster-autoscaler/cloudprovider/hetzner/dev/variables.tf b/cluster-autoscaler/cloudprovider/hetzner/dev/variables.tf new file mode 100644 index 000000000000..46b34057d0d4 --- /dev/null +++ b/cluster-autoscaler/cloudprovider/hetzner/dev/variables.tf @@ -0,0 +1,10 @@ +variable "name" { + type = string +} +variable "hcloud_token" { + type = string + sensitive = true +} +variable "k3s_channel" { + type = string +} diff --git a/cluster-autoscaler/cloudprovider/hetzner/examples/cloud-init.sh b/cluster-autoscaler/cloudprovider/hetzner/examples/cloud-init.sh new file mode 100644 index 000000000000..7f36da753c8a --- /dev/null +++ b/cluster-autoscaler/cloudprovider/hetzner/examples/cloud-init.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +export K3S_URL=https://YOUR_IP:6443 +# From /var/lib/rancher/k3s/server/token +export K3S_TOKEN=YOUR_TOKEN +export INSTALL_K3S_CHANNEL=v1.31 +EXTERNAL_IP=$(ip -4 addr show eth0 | grep -oP '(?<=inet\s)\d+(\.\d+){3}') +INTERNAL_IP=$(ip -4 addr show enp7s0 | grep -oP '(?<=inet\s)\d+(\.\d+){3}') +curl -sfL https://get.k3s.io | sh -s - --kubelet-arg=cloud-provider=external --node-external-ip $EXTERNAL_IP --node-ip $INTERNAL_IP diff --git a/cluster-autoscaler/cloudprovider/hetzner/examples/kustomization.yaml b/cluster-autoscaler/cloudprovider/hetzner/examples/kustomization.yaml new file mode 100644 index 000000000000..3ac9d001c89a --- /dev/null +++ b/cluster-autoscaler/cloudprovider/hetzner/examples/kustomization.yaml @@ -0,0 +1,12 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization + +namespace: kube-system + +resources: + - cluster-autoscaler-run-on-master.yaml + +secretGenerator: + - name: cluster-autoscaler-cloud-init + files: + - cloudinit=cloud-init.sh.b64 \ No newline at end of file diff --git a/cluster-autoscaler/cloudprovider/hetzner/skaffold.yaml b/cluster-autoscaler/cloudprovider/hetzner/skaffold.yaml new file mode 100644 index 000000000000..c148f71f5db3 --- /dev/null +++ b/cluster-autoscaler/cloudprovider/hetzner/skaffold.yaml @@ -0,0 +1,20 @@ +apiVersion: skaffold/v4beta3 +kind: Config +metadata: + name: cluster-autoscaler-hetzner +build: + artifacts: + - image: registry.k8s.io/autoscaling/cluster-autoscaler + context: ../../ + ko: + flags: + - -tags=hetzner + + local: + useBuildkit: true + insecureRegistries: + - localhost:30666 +manifests: + kustomize: + paths: + - examples/ \ No newline at end of file