Compare commits

..

1 commit

5 changed files with 86 additions and 70 deletions

View file

@ -2,122 +2,135 @@
# yaml-language-server: $schema=https://taskfile.dev/schema.json
version: "3"
vars:
RESOURCES_DIR: "{{.ROOT_DIR}}/.taskfiles/talos/resources"
CONTROLLER:
sh: talosctl --context {{.cluster}} config info --output json | jq --raw-output '.endpoints[]' | shuf -n 1
cluster: theshire
tasks:
bootstrap:
desc: Bootstrap Talos
summary: |
Args:
CONTROLLER: Controller node to run command against (required)
prompt: Bootstrap Talos on the '{{.K8S_CLUSTER}}' cluster... continue?
cluster: Cluster to run command against (default: theshire)
controller: Controller node to run command against (required) (IP/DNS)
dotenv: ["{{.RESOURCES_DIR}}/.env"]
prompt: Bootstrap Talos on the cluster... continue?
cmds:
- task: bootstrap-etcd
vars: &vars
CONTROLLER: "{{.CONTROLER}}"
controller: "{{.controller}}"
- task: fetch-kubeconfig
vars: *vars
- task: bootstrap-integrations
vars: *vars
requires:
vars:
- K8S_CLUSTER
- CONTROLLER
- controller
bootstrap-etcd:
desc: Bootstrap Etcd
cmd: until talosctl --nodes {{.CONTROLLER}} bootstrap; do sleep 10; done
dotenv: ["{{.RESOURCES_DIR}}/.env"]
cmd: until talosctl --context $CLUSTER --nodes {{.controller}} bootstrap; do sleep 10; done
requires:
vars:
- CONTROLLER
- controller
bootstrap-integrations:
desc: Bootstrap core integrations needed for Talos
dotenv: ["{{.RESOURCES_DIR}}/.env"]
cmds:
- until kubectl wait --for=condition=Ready=False nodes --all --timeout=600s; do sleep 10; done
- helmfile --kube-context {{.K8S_CLUSTER}} --file {{.K8S_CLUSTER_DIR}}/bootstrap/helmfile.yaml apply --skip-diff-on-install --suppress-diff
- until kubectl wait --for=condition=Ready nodes --all --timeout=600s; do sleep 10; done
requires:
vars:
- K8S_CLUSTER
- until kubectl --context $CLUSTER wait --for=condition=Ready=False nodes --all --timeout=600s; do sleep 10; done
- helmfile --kube-context $CLUSTER --file {{.KUBERNETES_DIR}}/bootstrap/helmfile.yaml apply --skip-diff-on-install --suppress-diff
- until kubectl --context $CLUSTER wait --for=condition=Ready nodes --all --timeout=600s; do sleep 10; done
preconditions:
- which helmfile
- sh: kubectl config get-contexts {{.K8S_CLUSTER}}
msg: "Kubectl context {{.K8S_CLUSTER}} not found"
- test -f {{.K8S_CLUSTER_DIR}}/bootstrap/helmfile.yaml
- sh: kubectl config get-contexts $CLUSTER
msg: "Kubectl context $CLUSTER not found"
- test -f {{.KUBERNETES_DIR}}/bootstrap/helmfile.yaml
fetch-kubeconfig:
desc: Fetch kubeconfig from Talos controllers
dotenv: ["{{.RESOURCES_DIR}}/.env"]
env: *vars
cmd: |
talosctl kubeconfig --nodes {{.CONTROLLER}} \
--force --force-context-name {{.K8S_CLUSTER}} {{.K8S_CLUSTER_DIR}}
requires:
vars:
- K8S_CLUSTER
talosctl --context $CLUSTER kubeconfig --nodes {{ .CONTROLLER }} \
--force --force-context-name $CLUSTER {{.ROOT_DIR}}/kubeconfig
preconditions:
- talosctl config get-contexts | grep $CLUSTER
generate-clusterconfig:
desc: Generate clusterconfig for Talos
dotenv: ["{{.RESOURCES_DIR}}/.env"]
cmds:
- talhelper genconfig
--env-file {{.K8S_CLUSTER_DIR}}/bootstrap/talos/talenv.sops.yaml
--secret-file {{.K8S_CLUSTER_DIR}}/bootstrap/talos/talsecret.sops.yaml
--config-file {{.K8S_CLUSTER_DIR}}/bootstrap/talos/talconfig.yaml
--out-dir {{.K8S_CLUSTER_DIR}}/bootstrap/talos/clusterconfig
requires:
vars:
- K8S_CLUSTER
--env-file {{.KUBERNETES_DIR}}/bootstrap/talos/talenv.sops.yaml
--secret-file {{.KUBERNETES_DIR}}/bootstrap/talos/talsecret.sops.yaml
--config-file {{.KUBERNETES_DIR}}/bootstrap/talos/talconfig.yaml
--out-dir {{.KUBERNETES_DIR}}/bootstrap/talos/clusterconfig
preconditions:
- test -f {{.K8S_CLUSTER_DIR}}/bootstrap/talos/talenv.sops.yaml
- test -f {{.K8S_CLUSTER_DIR}}/bootstrap/talos/talsecret.sops.yaml
- test -f {{.K8S_CLUSTER_DIR}}/bootstrap/talos/talconfig.yaml
- which talhelper
- test -f {{.KUBERNETES_DIR}}/bootstrap/talos/talenv.sops.yaml
- test -f {{.KUBERNETES_DIR}}/bootstrap/talos/talsecret.sops.yaml
- test -f {{.KUBERNETES_DIR}}/bootstrap/talos/talconfig.yaml
upgrade:
desc: Upgrade Talos version for a node
dotenv: ["{{.RESOURCES_DIR}}/.env"]
vars:
TALOS_VERSION:
sh: |
yq -r ".talosVersion" {{.K8S_CLUSTER_DIR}}/bootstrap/talos/talconfig.yaml
yq -r ".talosVersion" {{.KUBERNETES_DIR}}/bootstrap/talos/talconfig.yaml
TALOS_IMAGE:
sh: |
talhelper genurl installer \
--env-file {{.K8S_CLUSTER_DIR}}/bootstrap/talos/talenv.sops.yaml \
--config-file {{.K8S_CLUSTER_DIR}}/bootstrap/talos/talconfig.yaml \
| grep {{.NODE}} \
| awk '{split($0,u," "); print u[2]}'
--env-file {{.KUBERNETES_DIR}}/bootstrap/talos/talenv.sops.yaml \
--config-file {{.KUBERNETES_DIR}}/bootstrap/talos/talconfig.yaml
cmds:
- talosctl upgrade -n {{.NODE}} --image {{.TALOS_IMAGE }}
- talosctl --context $CLUSTER upgrade -n {{.node}} --image {{.TALOS_IMAGE }}
requires:
vars:
- K8S_CLUSTER
- NODE
- node
preconditions:
- test -f {{.K8S_CLUSTER_DIR}}/bootstrap/talos/talenv.sops.yaml
- test -f {{.K8S_CLUSTER_DIR}}/bootstrap/talos/talconfig.yaml
- msg: "Talos image could not be determined for node={{.NODE}}"
- which talhelper
- talosctl config get-contexts | grep $CLUSTER
- test -f {{.KUBERNETES_DIR}}/bootstrap/talos/talenv.sops.yaml
- test -f {{.KUBERNETES_DIR}}/bootstrap/talos/talconfig.yaml
- msg: "Talos image could not be determined for {{.node}}"
sh: 'test -n "{{.TALOS_IMAGE}}"'
upgrade-k8s:
desc: Upgrade Kubernetes version for a Talos cluster
silent: false
dotenv: ["{{.RESOURCES_DIR}}/.env"]
vars:
KUBERNETES_VERSION:
sh: |
yq -r ".kubernetesVersion" {{.K8S_CLUSTER_DIR}}/bootstrap/talos/talconfig.yaml
TALOS_CONTROLLER:
sh: talosctl config info --output json | jq --raw-output '.endpoints[]' | shuf -n 1
yq -r ".kubernetesVersion" {{.KUBERNETES_DIR}}/bootstrap/talos/talconfig.yaml
CONTROLPLANE_NODE:
sh: |
talosctl --context $CLUSTER config info \
| grep Endpoints: \
| awk '{split($0,u," "); print u[2]}' \
| sed -E 's/,//'
cmds:
- until kubectl wait --timeout=5m --for=condition=Complete jobs --all --all-namespaces; do sleep 10; done
- talosctl upgrade-k8s -n {{.TALOS_CONTROLLER}} --to {{.KUBERNETES_VERSION}}
requires:
vars:
- K8S_CLUSTER
- talosctl upgrade-k8s -n {{.CONTROLPLANE_NODE}} --to {{.KUBERNETES_VERSION}}
preconditions:
- talosctl config info &>/dev/null
- talosctl --nodes {{.TALOS_CONTROLLER}} get machineconfig &>/dev/null
- which talhelper
- talosctl config get-contexts | grep $CLUSTER
- test -f {{.KUBERNETES_DIR}}/bootstrap/talos/talenv.sops.yaml
- test -f {{.KUBERNETES_DIR}}/bootstrap/talos/talconfig.yaml
- msg: "Kubernetes version could not be determined for cluster $CLUSTER"
sh: 'test -n "{{.KUBERNETES_VERSION}}"'
- msg: "Control plane node could not be determined for cluster $CLUSTER"
sh: 'test -n "{{.CONTROLPLANE_NODE}}"'
apply-clusterconfig:
desc: Apply clusterconfig for a Talos cluster
dotenv: ["{{.RESOURCES_DIR}}/.env"]
vars:
CLUSTERCONFIG_FILES:
sh: find {{.K8S_CLUSTER_DIR}}/bootstrap/talos/clusterconfig -type f -name '*.yaml' -printf '%f\n'
sh: find {{.KUBERNETES_DIR}}/bootstrap/talos/clusterconfig -type f -name '*.yaml' -printf '%f\n'
cmds:
- for:
var: CLUSTERCONFIG_FILES
@ -125,24 +138,29 @@ tasks:
vars:
filename: "{{.ITEM}}"
hostname: |-
{{ trimPrefix (printf "%s-" .K8S_CLUSTER) .ITEM | trimSuffix ".yaml" }}
DRY_RUN: "{{ .DRY_RUN }}"
requires:
vars:
- K8S_CLUSTER
{{ trimPrefix (printf "%s-" .cluster) .ITEM | trimSuffix ".yaml" }}
dry_run: "{{ .dry_run }}"
preconditions:
- talosctl config get-contexts | grep $CLUSTER
- test -d {{.KUBERNETES_DIR}}/bootstrap/talos/clusterconfig
_apply-machineconfig:
internal: true
desc: Apply a single Talos machineConfig to a Talos node
dotenv: ["{{.RESOURCES_DIR}}/.env"]
cmds:
- talosctl apply-config
- talosctl --context theshire apply-config
--nodes "{{.hostname}}"
--file "{{.K8S_CLUSTER_DIR}}/bootstrap/talos/clusterconfig/{{.filename}}"
{{ if eq "true" .DRY_RUN }}--dry-run{{ end }}
--file "{{.KUBERNETES_DIR}}/bootstrap/talos/clusterconfig/{{.filename}}"
{{ if eq "true" .dry_run }}--dry-run{{ end }}
#--insecure
requires:
vars:
- K8S_CLUSTER
- hostname
- filename
preconditions:
- test -f {{.K8S_CLUSTER_DIR}}/bootstrap/talos/clusterconfig/{{.filename}}
- talosctl config get-contexts | grep $CLUSTER
- test -f {{.KUBERNETES_DIR}}/bootstrap/talos/clusterconfig/{{.filename}}
version:
desc: Show Talos version
cmd: talosctl version

View file

@ -0,0 +1 @@
CLUSTER=theshire

View file

@ -5,8 +5,6 @@ vars:
KUBERNETES_DIR: "{{.ROOT_DIR}}/kubernetes"
CLUSTER_SECRETS_FILE: "{{.CLUSTER_DIR}}/flux/vars/cluster-secrets.sops.env"
CLUSTER_SETTINGS_FILE: "{{.CLUSTER_DIR}}/flux/vars/cluster-settings.env"
K8S_CLUSTER: '{{.K8S_CLUSTER | default "theshire"}}'
K8S_CLUSTER_DIR: '{{.KUBERNETES_DIR}}'
env:
KUBECONFIG: "{{.ROOT_DIR}}/kubeconfig"

View file

@ -3,7 +3,7 @@
clusterName: theshire
talosVersion: v1.8.1
kubernetesVersion: 1.31.1
kubernetesVersion: 1.30.2
endpoint: "https://10.1.1.57:6444"
additionalApiServerCertSans:
@ -169,8 +169,8 @@ worker:
fs.inotify.max_queued_events: "65536"
fs.inotify.max_user_instances: "8192"
fs.inotify.max_user_watches: "524288"
net.core.rmem_max: "7500000"
net.core.wmem_max: "7500000"
net.core.rmem_max: "2500000"
net.core.wmem_max: "2500000"
- &nfsMountOptions |-
machine:
files:

View file

@ -19,6 +19,5 @@ pkgs.mkShell {
age
mqttui
kustomize
yq-go
];
}