From 60aa6ef237e3f033a064964898d89eef59291846 Mon Sep 17 00:00:00 2001 From: Serge Logvinov Date: Sat, 25 Dec 2021 00:41:26 +0200 Subject: [PATCH] Update readme --- hetzner/Makefile | 7 ++- hetzner/README.md | 60 ++++++++++++++----------- hetzner/instances-master.tf | 1 + hetzner/outputs.tf | 6 +++ hetzner/templates/controlplane.yaml.tpl | 9 ++++ hetzner/variables.tf | 2 +- 6 files changed, 54 insertions(+), 31 deletions(-) diff --git a/hetzner/Makefile b/hetzner/Makefile index eefad76..590b307 100644 --- a/hetzner/Makefile +++ b/hetzner/Makefile @@ -9,8 +9,7 @@ prepare: create-lb: ## Create load balancer terraform init - terraform apply -auto-approve -target=output.controlplane_endpoint - terraform output controlplane_endpoint + terraform apply -auto-approve -target=hcloud_floating_ip.api -target=hcloud_load_balancer.api create-config: ## Genereate talos configs talosctl gen config --output-dir _cfgs --with-docs=false --with-examples=false talos-k8s-hetzner https://${ENDPOINT}:6443 @@ -31,11 +30,11 @@ create-templates: @yq eval -o=json '{"kubernetes": .}' _cfgs/tfstate.vars > terraform.tfvars.json create-controlplane: ## Bootstrap first controlplane node - terraform apply -target=hcloud_server.controlplane + terraform apply -auto-approve -target=hcloud_server.controlplane create-infrastructure: ## Bootstrap all nodes cd modules/worker && terraform init terraform apply -create-kubeconfig: +create-kubeconfig: ## Prepare kubeconfig talosctl --talosconfig _cfgs/talosconfig --nodes 172.16.0.11 kubeconfig diff --git a/hetzner/README.md b/hetzner/README.md index 82f514a..79fc5e0 100644 --- a/hetzner/README.md +++ b/hetzner/README.md @@ -23,33 +23,18 @@ This terraform example install Talos on [HCloud](https://www.hetzner.com/cloud) ## Prepare the base image -First, prepare variables to your environment +Use packer (system_os/hetzner) to upload image. -```shell -export TF_VAR_hcloud_token=KEY -``` +## Create control plane lb -Terraform will run the VM in recovery mode, replace the base image and take a snapshote. Do not run terraform destroy after. It will delete the snapshot. - -```shell -make prepare-image -``` - -## Install control plane - -Generate the default talos config - -```shell -make create-config create-templates -``` - -open config file **terraform.tfvars** and add params +open config file **terraform.tfvars** and add params. ```hcl # counts and type of kubernetes master nodes controlplane = { - count = 1, - type = "cpx11" + count = 1, + type = "cpx11" + type_lb = "" } # regions to use @@ -58,15 +43,15 @@ regions = ["nbg1", "fsn1", "hel1"] # counts and type of worker nodes by redion instances = { "nbg1" = { - web_count = 1, + web_count = 0, web_instance_type = "cx11", - worker_count = 1, + worker_count = 0, worker_instance_type = "cx11", }, "fsn1" = { - web_count = 1, + web_count = 0, web_instance_type = "cx11", - worker_count = 1, + worker_count = 0, worker_instance_type = "cx11", } "hel1" = { @@ -78,13 +63,36 @@ instances = { } ``` +```shell +make create-lb +``` + +## Install control plane + +Generate the default talos config + +```shell +make create-config create-templates +``` + And deploy the kubernetes master nodes ```shell make create-controlplane ``` -Then deploy all other instances +Bootstrap the first node + +```shell +talosctl --talosconfig _cfgs/talosconfig config endpoint $controlplane_firstnode +talosctl --talosconfig _cfgs/talosconfig --nodes $controlplane_firstnode bootstrap +``` + +```shell +make create-kubeconfig +``` + +## Deploy all other instances ```shell make create-infrastructure diff --git a/hetzner/instances-master.tf b/hetzner/instances-master.tf index 686f73f..3fdaae7 100644 --- a/hetzner/instances-master.tf +++ b/hetzner/instances-master.tf @@ -26,6 +26,7 @@ resource "hcloud_server" "controlplane" { lbv6 = local.lbv6 hcloud_network = hcloud_network.main.id hcloud_token = var.hcloud_token + labels = "topology.kubernetes.io/region=${element(var.regions, count.index)}" }) ) diff --git a/hetzner/outputs.tf b/hetzner/outputs.tf index 71875cd..542c531 100644 --- a/hetzner/outputs.tf +++ b/hetzner/outputs.tf @@ -5,6 +5,12 @@ output "controlplane_endpoint" { depends_on = [hcloud_load_balancer.api] } +output "controlplane_firstnode" { + description = "Kubernetes controlplane first node" + value = hcloud_server.controlplane[0].ipv4_address +} + + output "controlplane_nodes" { description = "Kubernetes controlplane nodes" value = [ diff --git a/hetzner/templates/controlplane.yaml.tpl b/hetzner/templates/controlplane.yaml.tpl index 3f87e8a..4d1237a 100644 --- a/hetzner/templates/controlplane.yaml.tpl +++ b/hetzner/templates/controlplane.yaml.tpl @@ -14,6 +14,12 @@ machine: extraArgs: node-ip: "${ipv4_local}" rotate-server-certificates: true + node-labels: "${labels}" + clusterDNS: + - 169.254.2.53 + - ${cidrhost(split(",",serviceSubnets)[0], 10)} + nodeIP: + validSubnets: ${format("%#v",split(",",nodeSubnets))} network: hostname: "${name}" interfaces: @@ -49,6 +55,9 @@ machine: keys: - nodeID: {} slot: 0 + options: + - no_read_workqueue + - no_write_workqueue cluster: controlPlane: endpoint: https://${ipv4_vip}:6443 diff --git a/hetzner/variables.tf b/hetzner/variables.tf index edab61a..33eb9ef 100644 --- a/hetzner/variables.tf +++ b/hetzner/variables.tf @@ -45,7 +45,7 @@ variable "controlplane" { default = { count = 0, type = "cpx11" - type_lb = "" + type_lb = "" # lb11, if "" use floating-ip } }