Skip to content

Commit

Permalink
standardize k8s version and common setup steps in templates (#259)
Browse files Browse the repository at this point in the history
* standardize k8s version and common setup steps in templates
  • Loading branch information
eljohnson92 authored Apr 17, 2024
1 parent fa66dc0 commit 1b0a785
Show file tree
Hide file tree
Showing 13 changed files with 24 additions and 45 deletions.
2 changes: 1 addition & 1 deletion docs/src/topics/flavors/k3s.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/src/topics/flavors/rke2.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions templates/common-init-files/secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -39,6 +38,4 @@ stringData:
modprobe overlay
modprobe br_netfilter
sysctl --system
sed -i '/swap/d' /etc/fstab
swapoff -a
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}'
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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 }}'
6 changes: 4 additions & 2 deletions templates/flavors/default/kubeadmConfigTemplate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}'
7 changes: 4 additions & 3 deletions templates/flavors/default/kubeadmControlPlane.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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}"
3 changes: 1 addition & 2 deletions templates/flavors/k3s/k3sConfigTemplate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 2 additions & 3 deletions templates/flavors/k3s/k3sControlPlane.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
8 changes: 0 additions & 8 deletions templates/flavors/k3s/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
8 changes: 0 additions & 8 deletions templates/flavors/rke2/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
5 changes: 1 addition & 4 deletions templates/flavors/rke2/rke2ConfigTemplate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
- |
Expand Down
5 changes: 1 addition & 4 deletions templates/flavors/rke2/rke2ControlPlane.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down

0 comments on commit 1b0a785

Please sign in to comment.