Skip to content

Commit

Permalink
Merge pull request #337 from vitobotta:misc-updates
Browse files Browse the repository at this point in the history
Misc updates
  • Loading branch information
vitobotta authored Apr 12, 2024
2 parents da25a21 + e68cafa commit 56d6da7
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 22 deletions.
6 changes: 5 additions & 1 deletion .zshrc
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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://....
Expand Down
7 changes: 4 additions & 3 deletions cluster_config.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -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://....
Expand Down
7 changes: 4 additions & 3 deletions src/configuration/main.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 7 additions & 6 deletions src/kubernetes/installer.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand All @@ -289,7 +289,7 @@ class Kubernetes::Installer

unless result.success?
puts "Failed to deploy CSI Driver:"
puts result
puts result.output
exit 1
end

Expand All @@ -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

Expand Down Expand Up @@ -346,7 +347,7 @@ class Kubernetes::Installer

unless result.success?
puts "Failed to deploy Cluster Autoscaler:"
puts result
puts result.output
exit 1
end

Expand Down
14 changes: 14 additions & 0 deletions src/util/prefixed_io.cr
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion src/util/ssh.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ require "io"
require "../util"
require "retriable"
require "tasker"
require "./prefixed_io"

class Util::SSH
getter private_ssh_key_path : String
Expand Down Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions templates/cluster_autoscaler.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions templates/master_install_script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down

0 comments on commit 56d6da7

Please sign in to comment.