From 9a37d4bbcb11221b5c0f0ee91ebe67aaf54a5db8 Mon Sep 17 00:00:00 2001 From: Evan Johnson Date: Wed, 17 Apr 2024 14:02:56 -0400 Subject: [PATCH 1/2] 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 | 5 ++++- .../clusterclass-kubeadm/kubeadmControlPlaneTemplate.yaml | 7 ++++--- templates/flavors/default/kubeadmConfigTemplate.yaml | 6 ++++-- templates/flavors/default/kubeadmControlPlane.yaml | 5 ++++- 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(+), 42 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..4c69baa4e 100644 --- a/templates/flavors/clusterclass-kubeadm/kubeadmConfigTemplate.yaml +++ b/templates/flavors/clusterclass-kubeadm/kubeadmConfigTemplate.yaml @@ -28,7 +28,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 joinConfiguration: nodeRegistration: kubeletExtraArgs: 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..70f21ff32 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: 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/ From 9c975b171b55b125d4030dea01ab8d789fd1be5e Mon Sep 17 00:00:00 2001 From: Evan Johnson Date: Wed, 17 Apr 2024 15:09:53 -0400 Subject: [PATCH 2/2] remove additional provider-id settings --- .../flavors/clusterclass-kubeadm/kubeadmConfigTemplate.yaml | 1 - templates/flavors/default/kubeadmControlPlane.yaml | 2 -- 2 files changed, 3 deletions(-) diff --git a/templates/flavors/clusterclass-kubeadm/kubeadmConfigTemplate.yaml b/templates/flavors/clusterclass-kubeadm/kubeadmConfigTemplate.yaml index 4c69baa4e..74621f524 100644 --- a/templates/flavors/clusterclass-kubeadm/kubeadmConfigTemplate.yaml +++ b/templates/flavors/clusterclass-kubeadm/kubeadmConfigTemplate.yaml @@ -36,5 +36,4 @@ spec: 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 70f21ff32..62db33029 100644 --- a/templates/flavors/default/kubeadmControlPlane.yaml +++ b/templates/flavors/default/kubeadmControlPlane.yaml @@ -54,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}"