From 1abd872b5f39697cd6b24e4a9edda0859b354eee Mon Sep 17 00:00:00 2001 From: Evan Date: Wed, 17 Apr 2024 15:48:55 -0400 Subject: [PATCH] standardize k8s version and common setup steps in templates (#259) * standardize k8s version and common setup steps in templates --- docs/src/topics/flavors/k3s.md | 2 +- docs/src/topics/flavors/rke2.md | 2 +- templates/common-init-files/secret.yaml | 5 +---- .../clusterclass-kubeadm/kubeadmConfigTemplate.yaml | 6 ++++-- .../clusterclass-kubeadm/kubeadmControlPlaneTemplate.yaml | 7 ++++--- templates/flavors/default/kubeadmConfigTemplate.yaml | 6 ++++-- templates/flavors/default/kubeadmControlPlane.yaml | 7 ++++--- templates/flavors/k3s/k3sConfigTemplate.yaml | 3 +-- templates/flavors/k3s/k3sControlPlane.yaml | 5 ++--- templates/flavors/k3s/kustomization.yaml | 8 -------- templates/flavors/rke2/kustomization.yaml | 8 -------- templates/flavors/rke2/rke2ConfigTemplate.yaml | 5 +---- templates/flavors/rke2/rke2ControlPlane.yaml | 5 +---- 13 files changed, 24 insertions(+), 45 deletions(-) diff --git a/docs/src/topics/flavors/k3s.md b/docs/src/topics/flavors/k3s.md index 0eef945cb..944c34a4d 100644 --- a/docs/src/topics/flavors/k3s.md +++ b/docs/src/topics/flavors/k3s.md @@ -7,7 +7,7 @@ * [Quickstart](../getting-started.md) completed * Select a [k3s kubernetes version](https://github.com/k3s-io/k3s/releases) to set for the kubernetes version ```bash - export K3S_KUBERNETES_VERSION=v1.29.1+k3s2 + export KUBERNETES_VERSION=v1.29.1+k3s2 ``` * Installed [k3s bootstrap provider](https://github.com/k3s-io/cluster-api-k3s) into your management cluster * Add the following to `~/.cluster-api/clusterctl.yaml` for the k3s bootstrap/control plane providers diff --git a/docs/src/topics/flavors/rke2.md b/docs/src/topics/flavors/rke2.md index e42e07597..8a772689f 100644 --- a/docs/src/topics/flavors/rke2.md +++ b/docs/src/topics/flavors/rke2.md @@ -7,7 +7,7 @@ * [Quickstart](../getting-started.md) completed * Select an [rke2 kubernetes version](https://github.com/rancher/rke2/releases) to set for the kubernetes version ```bash - export RKE2_KUBERNETES_VERSION=v1.29.1+rke2r1 + export KUBERNETES_VERSION=v1.29.1+rke2r1 ``` * Installed [rke2 bootstrap provider](https://github.com/rancher-sandbox/cluster-api-provider-rke2) into your management cluster ```shell diff --git a/templates/common-init-files/secret.yaml b/templates/common-init-files/secret.yaml index b3e8246c6..1cfba34ff 100644 --- a/templates/common-init-files/secret.yaml +++ b/templates/common-init-files/secret.yaml @@ -27,9 +27,8 @@ stringData: #!/bin/bash set -euo pipefail export DEBIAN_FRONTEND=noninteractive - hostnamectl set-hostname "$1" && hostname -F /etc/hostname mkdir -p -m 755 /etc/apt/keyrings - PATCH_VERSION=$${2#[v]} + PATCH_VERSION=$${1#[v]} VERSION=$${PATCH_VERSION%.*} curl -fsSL "https://pkgs.k8s.io/core:/stable:/v$VERSION/deb/Release.key" | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg echo "deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v$VERSION/deb/ /" | sudo tee /etc/apt/sources.list.d/kubernetes.list @@ -39,6 +38,4 @@ stringData: modprobe overlay modprobe br_netfilter sysctl --system - sed -i '/swap/d' /etc/fstab - swapoff -a diff --git a/templates/flavors/clusterclass-kubeadm/kubeadmConfigTemplate.yaml b/templates/flavors/clusterclass-kubeadm/kubeadmConfigTemplate.yaml index c19aa3002..74621f524 100644 --- a/templates/flavors/clusterclass-kubeadm/kubeadmConfigTemplate.yaml +++ b/templates/flavors/clusterclass-kubeadm/kubeadmConfigTemplate.yaml @@ -28,10 +28,12 @@ spec: key: kubeadm-pre-init.sh permissions: "0500" preKubeadmCommands: - - /kubeadm-pre-init.sh '{{ ds.meta_data.label }}' ${KUBERNETES_VERSION} + - /kubeadm-pre-init.sh ${KUBERNETES_VERSION} + - sed -i '/swap/d' /etc/fstab + - swapoff -a + - hostnamectl set-hostname '{{ ds.meta_data.label }}' && hostname -F /etc/hostname joinConfiguration: nodeRegistration: kubeletExtraArgs: cloud-provider: external - provider-id: 'linode://{{ ds.meta_data.id }}' name: '{{ ds.meta_data.label }}' diff --git a/templates/flavors/clusterclass-kubeadm/kubeadmControlPlaneTemplate.yaml b/templates/flavors/clusterclass-kubeadm/kubeadmControlPlaneTemplate.yaml index 3706ca386..ae8bce0ac 100644 --- a/templates/flavors/clusterclass-kubeadm/kubeadmControlPlaneTemplate.yaml +++ b/templates/flavors/clusterclass-kubeadm/kubeadmControlPlaneTemplate.yaml @@ -29,7 +29,10 @@ spec: key: kubeadm-pre-init.sh permissions: "0500" preKubeadmCommands: - - /kubeadm-pre-init.sh '{{ ds.meta_data.label }}' "${KUBERNETES_VERSION}" + - /kubeadm-pre-init.sh ${KUBERNETES_VERSION} + - sed -i '/swap/d' /etc/fstab + - swapoff -a + - hostnamectl set-hostname '{{ ds.meta_data.label }}' && hostname -F /etc/hostname clusterConfiguration: etcd: local: @@ -54,11 +57,9 @@ spec: nodeRegistration: kubeletExtraArgs: cloud-provider: external - provider-id: 'linode://{{ ds.meta_data.id }}' name: '{{ ds.meta_data.label }}' joinConfiguration: nodeRegistration: kubeletExtraArgs: cloud-provider: external - provider-id: 'linode://{{ ds.meta_data.id }}' name: '{{ ds.meta_data.label }}' diff --git a/templates/flavors/default/kubeadmConfigTemplate.yaml b/templates/flavors/default/kubeadmConfigTemplate.yaml index fc938e122..0fd5c0fbf 100644 --- a/templates/flavors/default/kubeadmConfigTemplate.yaml +++ b/templates/flavors/default/kubeadmConfigTemplate.yaml @@ -29,10 +29,12 @@ spec: key: kubeadm-pre-init.sh permissions: "0500" preKubeadmCommands: - - /kubeadm-pre-init.sh '{{ ds.meta_data.label }}' "${KUBERNETES_VERSION}" + - /kubeadm-pre-init.sh ${KUBERNETES_VERSION} + - sed -i '/swap/d' /etc/fstab + - swapoff -a + - hostnamectl set-hostname '{{ ds.meta_data.label }}' && hostname -F /etc/hostname joinConfiguration: nodeRegistration: kubeletExtraArgs: cloud-provider: external - provider-id: 'linode://{{ ds.meta_data.id }}' name: '{{ ds.meta_data.label }}' diff --git a/templates/flavors/default/kubeadmControlPlane.yaml b/templates/flavors/default/kubeadmControlPlane.yaml index 9eb594dc2..62db33029 100644 --- a/templates/flavors/default/kubeadmControlPlane.yaml +++ b/templates/flavors/default/kubeadmControlPlane.yaml @@ -34,7 +34,10 @@ spec: key: kubeadm-pre-init.sh permissions: "0500" preKubeadmCommands: - - /kubeadm-pre-init.sh '{{ ds.meta_data.label }}' "${KUBERNETES_VERSION}" + - /kubeadm-pre-init.sh ${KUBERNETES_VERSION} + - sed -i '/swap/d' /etc/fstab + - swapoff -a + - hostnamectl set-hostname '{{ ds.meta_data.label }}' && hostname -F /etc/hostname clusterConfiguration: etcd: local: @@ -51,12 +54,10 @@ spec: nodeRegistration: kubeletExtraArgs: cloud-provider: external - provider-id: 'linode://{{ ds.meta_data.id }}' name: '{{ ds.meta_data.label }}' joinConfiguration: nodeRegistration: kubeletExtraArgs: cloud-provider: external - provider-id: 'linode://{{ ds.meta_data.id }}' name: '{{ ds.meta_data.label }}' version: "${KUBERNETES_VERSION}" diff --git a/templates/flavors/k3s/k3sConfigTemplate.yaml b/templates/flavors/k3s/k3sConfigTemplate.yaml index 9127f4eab..a3e8570c2 100644 --- a/templates/flavors/k3s/k3sConfigTemplate.yaml +++ b/templates/flavors/k3s/k3sConfigTemplate.yaml @@ -8,11 +8,10 @@ spec: spec: agentConfig: nodeName: '{{ ds.meta_data.label }}' - kubeletArgs: - - "provider-id=linode://{{ ds.meta_data.id }}" preK3sCommands: - | mkdir -p /etc/rancher/k3s/config.yaml.d/ echo "node-ip: $(hostname -I | grep -oE 192\.168\.[0-9]+\.[0-9]+)" >> /etc/rancher/k3s/config.yaml.d/capi-config.yaml - sed -i '/swap/d' /etc/fstab - swapoff -a + - hostnamectl set-hostname '{{ ds.meta_data.label }}' && hostname -F /etc/hostname diff --git a/templates/flavors/k3s/k3sControlPlane.yaml b/templates/flavors/k3s/k3sControlPlane.yaml index 0b19633b3..3600642bc 100644 --- a/templates/flavors/k3s/k3sControlPlane.yaml +++ b/templates/flavors/k3s/k3sControlPlane.yaml @@ -39,12 +39,11 @@ spec: - traefik agentConfig: nodeName: '{{ ds.meta_data.label }}' - kubeletArgs: - - "provider-id=linode://{{ ds.meta_data.id }}" preK3sCommands: - | echo "node-ip: $(hostname -I | grep -oE 192\.168\.[0-9]+\.[0-9]+)" >> /etc/rancher/k3s/config.yaml.d/capi-config.yaml - sed -i '/swap/d' /etc/fstab - swapoff -a + - hostnamectl set-hostname '{{ ds.meta_data.label }}' && hostname -F /etc/hostname replicas: ${CONTROL_PLANE_MACHINE_COUNT} - version: ${K3S_KUBERNETES_VERSION} + version: ${KUBERNETES_VERSION} diff --git a/templates/flavors/k3s/kustomization.yaml b/templates/flavors/k3s/kustomization.yaml index 82dd783db..76801b133 100644 --- a/templates/flavors/k3s/kustomization.yaml +++ b/templates/flavors/k3s/kustomization.yaml @@ -22,11 +22,3 @@ patches: - op: replace path: /spec/template/spec/bootstrap/configRef/kind value: KThreesConfigTemplate - - target: - group: cluster.x-k8s.io - version: v1beta1 - kind: MachineDeployment - patch: |- - - op: replace - path: /spec/template/spec/version - value: ${K3S_KUBERNETES_VERSION} diff --git a/templates/flavors/rke2/kustomization.yaml b/templates/flavors/rke2/kustomization.yaml index 34108ba7f..fdfed62da 100644 --- a/templates/flavors/rke2/kustomization.yaml +++ b/templates/flavors/rke2/kustomization.yaml @@ -22,11 +22,3 @@ patches: - op: replace path: /spec/template/spec/bootstrap/configRef/kind value: RKE2ConfigTemplate - - target: - group: cluster.x-k8s.io - version: v1beta1 - kind: MachineDeployment - patch: |- - - op: replace - path: /spec/template/spec/version - value: ${RKE2_KUBERNETES_VERSION} diff --git a/templates/flavors/rke2/rke2ConfigTemplate.yaml b/templates/flavors/rke2/rke2ConfigTemplate.yaml index 8d2a0feff..c610c5bc6 100644 --- a/templates/flavors/rke2/rke2ConfigTemplate.yaml +++ b/templates/flavors/rke2/rke2ConfigTemplate.yaml @@ -7,11 +7,8 @@ spec: template: spec: agentConfig: - version: ${RKE2_KUBERNETES_VERSION} + version: ${KUBERNETES_VERSION} nodeName: '{{ ds.meta_data.label }}' - kubelet: - extraArgs: - - "provider-id=linode://{{ ds.meta_data.id }}" # TODO: use MDS to get public and private IP instead because hostname ordering can't always be assumed preRKE2Commands: - | diff --git a/templates/flavors/rke2/rke2ControlPlane.yaml b/templates/flavors/rke2/rke2ControlPlane.yaml index a2178ac83..6f9dfc1bb 100644 --- a/templates/flavors/rke2/rke2ControlPlane.yaml +++ b/templates/flavors/rke2/rke2ControlPlane.yaml @@ -31,11 +31,8 @@ spec: kubernetesComponents: - "cloudController" agentConfig: - version: ${RKE2_KUBERNETES_VERSION} + version: ${KUBERNETES_VERSION} nodeName: '{{ ds.meta_data.label }}' - kubelet: - extraArgs: - - "provider-id=linode://{{ ds.meta_data.id }}" preRKE2Commands: - | mkdir -p /etc/rancher/rke2/config.yaml.d/