From 36f8a6c17b4896ba8b422b5818bb17ef4218fee6 Mon Sep 17 00:00:00 2001 From: Devin Buhl Date: Tue, 29 Oct 2024 10:58:40 -0400 Subject: [PATCH] chore: improve apply-config task and update readme Signed-off-by: Devin Buhl --- .taskfiles/talos/Taskfile.yaml | 21 ++++++++++-- README.md | 58 +++++++++++++++++++++------------- 2 files changed, 54 insertions(+), 25 deletions(-) diff --git a/.taskfiles/talos/Taskfile.yaml b/.taskfiles/talos/Taskfile.yaml index fde7d7f2..c2943f32 100644 --- a/.taskfiles/talos/Taskfile.yaml +++ b/.taskfiles/talos/Taskfile.yaml @@ -5,6 +5,7 @@ version: '3' vars: TALHELPER_CLUSTER_DIR: '{{.KUBERNETES_DIR}}/bootstrap/talos/clusterconfig' TALHELPER_CONFIG_FILE: '{{.KUBERNETES_DIR}}/bootstrap/talos/talconfig.yaml' + TALHELPER_SECRET_FILE: '{{.KUBERNETES_DIR}}/bootstrap/talos/talsecret.sops.yaml' TALOSCONFIG: '{{.TALHELPER_CLUSTER_DIR}}/talosconfig' env: @@ -12,9 +13,24 @@ env: tasks: + generate-config: + desc: Generate Talos configuration + cmd: talhelper genconfig --config-file {{.TALHELPER_CONFIG_FILE}} --secret-file {{.TALHELPER_SECRET_FILE}} --out-dir {{.TALHELPER_CLUSTER_DIR}} + preconditions: + - msg: Missing talhelper config file + sh: test -f {{.TALHELPER_CONFIG_FILE}} + - msg: Missing Sops config file + sh: test -f {{.SOPS_CONFIG_FILE}} + - msg: Missing Sops Age key file + sh: test -f {{.SOPS_AGE_KEY_FILE}} + apply-config: desc: Apply Talos configuration to a node - cmd: talosctl apply-config --mode={{.MODE}} --nodes {{.HOSTNAME}} --file {{.TALHELPER_CLUSTER_DIR}}/{{.CLUSTER_NAME}}-{{.HOSTNAME}}.yaml + cmds: + - '{{if eq .MODE "reboot"}}kubectl drain {{.HOSTNAME}} --ignore-daemonsets --delete-emptydir-data --force{{end}}' + - talosctl apply-config --mode={{.MODE}} --nodes {{.HOSTNAME}} --file {{.TALHELPER_CLUSTER_DIR}}/{{.CLUSTER_NAME}}-{{.HOSTNAME}}.yaml + - talosctl --nodes {{.HOSTNAME}} health --wait-timeout=10m --server=false + - '{{if eq .MODE "reboot"}}kubectl uncordon {{.HOSTNAME}}{{end}}' vars: MODE: '{{.MODE | default "no-reboot"}}' CLUSTER_NAME: @@ -71,8 +87,7 @@ tasks: upgrade-k8s: desc: Upgrade Kubernetes - cmds: - - talosctl --nodes {{.KUBERNETES_CONTROLLER}} upgrade-k8s --to {{.KUBERNETES_VERSION}} + cmd: talosctl --nodes {{.KUBERNETES_CONTROLLER}} upgrade-k8s --to {{.KUBERNETES_VERSION}} vars: KUBERNETES_CONTROLLER: sh: talosctl config info --output json | jq --raw-output '.endpoints[]' | shuf -n 1 diff --git a/README.md b/README.md index 2edb2f80..7d29682b 100644 --- a/README.md +++ b/README.md @@ -288,6 +288,42 @@ There might be a situation where you want to destroy your Kubernetes cluster. Th task talos:reset # --force ``` +## 🛠️ Talos and Kubernetes Maintenance + +#### ⚙️ Updating Talos node configuration + +📍 _Ensure you have updated `talconfig.yaml` and any patches with your updated configuration._ + +```sh +# (Re)generate the Talos config +task talos:generate-config +# Apply the config to the node +task talos:apply-config HOSTNAME=? MODE=? +# e.g. task talos:apply-config HOSTNAME=k8s-0 MODE=reboot +``` + +#### ⬆️ Updating Talos and Kubernetes versions + +📍 _Ensure the `talosVersion` and `kubernetesVersion` in `talhelper.yaml` are up-to-date with the version you wish to upgrade to._ + +```sh +# Upgrade the whole cluster to a newer Talos version +task talos:upgrade-cluster +# e.g. task talos:upgrade-cluster +``` + +```sh +# Upgrade node to a newer Talos version +task talos:upgrade-node HOSTNAME=? +# e.g. task talos:upgrade HOSTNAME=k8s-0 +``` + +```sh +# Upgrade cluster to a newer Kubernetes version +task talos:upgrade-k8s +# e.g. task talos:upgrade-k8s +``` + ## 🤖 Renovate [Renovate](https://www.mend.io/renovate) is a tool that automates dependency management. It is designed to scan your repository around the clock and open PRs for out-of-date dependencies it finds. Common dependencies it can discover are Helm charts, container images, GitHub Actions, Ansible roles... even Flux itself! Merging a PR will cause Flux to apply the update to your cluster. @@ -342,28 +378,6 @@ Below is a general guide on trying to debug an issue with an resource or applica Resolving problems that you have could take some tweaking of your YAML manifests in order to get things working, other times it could be a external factor like permissions on NFS. If you are unable to figure out your problem see the help section below. -## ⬆️ Upgrading Talos and Kubernetes - -📍 _Ensure the `talosVersion` and `kubernetesVersion` in `talhelper.yaml` are up-to-date with the version you wish to upgrade to._ - -```sh -# Upgrade the whole cluster to a newer Talos version -task talos:upgrade-cluster -# e.g. task talos:upgrade-cluster -``` - -```sh -# Upgrade node to a newer Talos version -task talos:upgrade-node HOSTNAME=? -# e.g. task talos:upgrade HOSTNAME=k8s-0 -``` - -```sh -# Upgrade cluster to a newer Kubernetes version -task talos:upgrade-k8s -# e.g. task talos:upgrade-k8s -``` - ## 👉 Help - Make a post in this repository's Github [Discussions](https://github.com/onedr0p/cluster-template/discussions).