diff --git a/.zshrc b/.zshrc index b72cbd0..1d86132 100644 --- a/.zshrc +++ b/.zshrc @@ -56,4 +56,8 @@ set +a echo "*" > /home/app/hetzner-k3s/tmp/.gitignore echo "!.gitignore" >> /home/app/hetzner-k3s/tmp/.gitignore -eval `ssh-agent` +eval "$(ssh-agent -s)" + +ssh-add -k ~/.ssh/id_*[!.pub] + +clear diff --git a/README.md b/README.md index c70f3cf..d3b02b8 100644 --- a/README.md +++ b/README.md @@ -157,9 +157,10 @@ schedule_workloads_on_masters: false # image: rocky-9 # optional: default is ubuntu-22.04 # autoscaling_image: 103908130 # optional, defaults to the `image` setting # snapshot_os: microos # optional: specified the os type when using a custom snapshot -cloud_controller_manager_manifest_url: "https://github.com/hetznercloud/hcloud-cloud-controller-manager/releases/download/v1.18.0/ccm-networks.yaml" -csi_driver_manifest_url: "https://raw.githubusercontent.com/hetznercloud/csi-driver/v2.5.1/deploy/kubernetes/hcloud-csi.yml" -system_upgrade_controller_manifest_url: "https://raw.githubusercontent.com/rancher/system-upgrade-controller/master/manifests/system-upgrade-controller.yaml" +# cloud_controller_manager_manifest_url: "https://github.com/hetznercloud/hcloud-cloud-controller-manager/releases/download/v1.19.0/ccm-networks.yaml" +# csi_driver_manifest_url: "https://raw.githubusercontent.com/hetznercloud/csi-driver/v2.6.0/deploy/kubernetes/hcloud-csi.yml" +# system_upgrade_controller_config_manifest_url: "https://github.com/rancher/system-upgrade-controller/releases/latest/download/system-upgrade-controller.yaml" +# system_upgrade_controller_crd_manifest_url: "https://github.com/rancher/system-upgrade-controller/releases/latest/download/crd.yaml" datastore: mode: etcd # etcd (default) or external external_datastore_endpoint: postgres://.... diff --git a/cluster_config.yaml.example b/cluster_config.yaml.example index 18ee20e..8a476e9 100644 --- a/cluster_config.yaml.example +++ b/cluster_config.yaml.example @@ -22,9 +22,10 @@ disable_flannel: false # set to true if you want to install a different CNI # image: rocky-9 # optional: default is ubuntu-22.04 # autoscaling_image: 103908130 # optional, defaults to the `image` setting # snapshot_os: microos # optional: specified the os type when using a custom snapshot -cloud_controller_manager_manifest_url: "https://raw.githubusercontent.com/hetznercloud/hcloud-cloud-controller-manager/v1.18.0/deploy/ccm-networks.yaml" -csi_driver_manifest_url: "https://raw.githubusercontent.com/hetznercloud/csi-driver/v2.5.1/deploy/kubernetes/hcloud-csi.yml" -system_upgrade_controller_manifest_url: "https://raw.githubusercontent.com/rancher/system-upgrade-controller/master/manifests/system-upgrade-controller.yaml" +# cloud_controller_manager_manifest_url: "https://github.com/hetznercloud/hcloud-cloud-controller-manager/releases/download/v1.19.0/ccm-networks.yaml" +# csi_driver_manifest_url: "https://raw.githubusercontent.com/hetznercloud/csi-driver/v2.6.0/deploy/kubernetes/hcloud-csi.yml" +# system_upgrade_controller_config_manifest_url: "https://github.com/rancher/system-upgrade-controller/releases/latest/download/system-upgrade-controller.yaml" +# system_upgrade_controller_crd_manifest_url: "https://github.com/rancher/system-upgrade-controller/releases/latest/download/crd.yaml" datastore: mode: etcd # etcd (default) or external external_datastore_endpoint: postgres://.... diff --git a/src/configuration/main.cr b/src/configuration/main.cr index ade0177..a2b4e5d 100644 --- a/src/configuration/main.cr +++ b/src/configuration/main.cr @@ -39,9 +39,10 @@ class Configuration::Main getter cluster_cidr : String = "10.244.0.0/16" getter service_cidr : String = "10.43.0.0/16" getter cluster_dns : String = "10.43.0.10" - getter cloud_controller_manager_manifest_url : String = "https://raw.githubusercontent.com/hetznercloud/hcloud-cloud-controller-manager/v1.18.0/deploy/ccm-networks.yaml" - getter csi_driver_manifest_url : String = "https://raw.githubusercontent.com/hetznercloud/csi-driver/v2.5.1/deploy/kubernetes/hcloud-csi.yml" - getter system_upgrade_controller_manifest_url : String = "https://raw.githubusercontent.com/rancher/system-upgrade-controller/master/manifests/system-upgrade-controller.yaml" + getter cloud_controller_manager_manifest_url : String = "https://github.com/hetznercloud/hcloud-cloud-controller-manager/releases/download/v1.19.0/ccm-networks.yaml" + getter csi_driver_manifest_url : String = "https://raw.githubusercontent.com/hetznercloud/csi-driver/v2.6.0/deploy/kubernetes/hcloud-csi.yml" + getter system_upgrade_controller_config_manifest_url : String = "https://github.com/rancher/system-upgrade-controller/releases/latest/download/system-upgrade-controller.yaml" + getter system_upgrade_controller_crd_manifest_url : String = "https://github.com/rancher/system-upgrade-controller/releases/latest/download/crd.yaml" getter disable_flannel : Bool = false getter ssh_port : Int32 = 22 getter datastore : Configuration::Datastore = Configuration::Datastore.new diff --git a/src/kubernetes/installer.cr b/src/kubernetes/installer.cr index 5bc7cae..3bdb700 100644 --- a/src/kubernetes/installer.cr +++ b/src/kubernetes/installer.cr @@ -242,7 +242,7 @@ class Kubernetes::Installer unless result.success? puts "Failed to create Hetzner Cloud secret:" - puts result + puts result.output exit 1 end @@ -273,7 +273,7 @@ class Kubernetes::Installer unless result.success? puts "Failed to deploy Cloud Controller Manager:" - puts result + puts result.output exit 1 end @@ -289,7 +289,7 @@ class Kubernetes::Installer unless result.success? puts "Failed to deploy CSI Driver:" - puts result + puts result.output exit 1 end @@ -299,13 +299,14 @@ class Kubernetes::Installer private def deploy_system_upgrade_controller puts "\nDeploying k3s System Upgrade Controller..." - command = "kubectl apply -f #{settings.system_upgrade_controller_manifest_url}" + # Run second manifest twice to fix problem with namespace creation + command = "kubectl apply -f #{settings.system_upgrade_controller_config_manifest_url},#{settings.system_upgrade_controller_crd_manifest_url},#{settings.system_upgrade_controller_crd_manifest_url}" result = Util::Shell.run(command, configuration.kubeconfig_path, settings.hetzner_token) unless result.success? puts "Failed to deploy k3s System Upgrade Controller:" - puts result + puts result.output exit 1 end @@ -346,7 +347,7 @@ class Kubernetes::Installer unless result.success? puts "Failed to deploy Cluster Autoscaler:" - puts result + puts result.output exit 1 end diff --git a/src/util/prefixed_io.cr b/src/util/prefixed_io.cr new file mode 100644 index 0000000..15ddd71 --- /dev/null +++ b/src/util/prefixed_io.cr @@ -0,0 +1,14 @@ +class PrefixedIO < IO + def initialize(@prefix : String, @io : IO); end + + def read(slice : Bytes) + raise NotImplementedError.new "#read" + end + + def write(slice : Bytes) : Nil + content = String.new(slice) + content.lines.each do |line| + @io << @prefix << "#{line}\n" + end + end +end diff --git a/src/util/ssh.cr b/src/util/ssh.cr index 5a7bba2..73b83c2 100644 --- a/src/util/ssh.cr +++ b/src/util/ssh.cr @@ -3,6 +3,7 @@ require "io" require "../util" require "retriable" require "tasker" +require "./prefixed_io" class Util::SSH getter private_ssh_key_path : String @@ -42,7 +43,7 @@ class Util::SSH result = IO::Memory.new all_output = if print_output - IO::MultiWriter.new(STDOUT, result) + IO::MultiWriter.new(PrefixedIO.new("[#{server.name}] ", STDOUT), result) else IO::MultiWriter.new(result) end diff --git a/templates/cluster_autoscaler.yaml b/templates/cluster_autoscaler.yaml index ee43ea0..760737d 100644 --- a/templates/cluster_autoscaler.yaml +++ b/templates/cluster_autoscaler.yaml @@ -140,22 +140,22 @@ spec: serviceAccountName: cluster-autoscaler tolerations: - effect: NoSchedule - key: node-role.kubernetes.io/master + key: node-role.kubernetes.io/control-plane - effect: NoExecute key: CriticalAddonsOnly value: "true" - # Node affinity is used to force cluster-autoscaler to stick - # to the master node. This allows the cluster to reliably downscale + # Node affinity is used to force cluster-autoscaler to stick + # to the control-plane node. This allows the cluster to reliably downscale # to zero worker nodes when needed. affinity: nodeAffinity: requiredDuringSchedulingIgnoredDuringExecution: nodeSelectorTerms: - matchExpressions: - - key: node-role.kubernetes.io/master + - key: node-role.kubernetes.io/control-plane operator: Exists containers: - - image: registry.k8s.io/autoscaling/cluster-autoscaler:v1.28.0 + - image: registry.k8s.io/autoscaling/cluster-autoscaler:v1.29.0 # or your custom image name: cluster-autoscaler resources: limits: diff --git a/templates/master_install_script.sh b/templates/master_install_script.sh index 3132844..326bacc 100644 --- a/templates/master_install_script.sh +++ b/templates/master_install_script.sh @@ -18,6 +18,7 @@ fi curl -sfL https://get.k3s.io | INSTALL_K3S_VERSION="{{ k3s_version }}" K3S_TOKEN="{{ k3s_token }}" {{ datastore_endpoint }} INSTALL_K3S_EXEC="server \ --disable-cloud-controller \ +--disable-network-policy \ --disable servicelb \ --disable traefik \ --disable local-storage \