From 1f86d017ec472b974077667e703115d06afcfa29 Mon Sep 17 00:00:00 2001 From: Evan Johnson Date: Mon, 26 Feb 2024 11:57:11 -0500 Subject: [PATCH] add k3s flavor support --- templates/flavors/k3s/k3sConfigTemplate.yaml | 18 +++++++ templates/flavors/k3s/k3sControlPlane.yaml | 50 ++++++++++++++++++++ templates/flavors/k3s/kustomization.yaml | 22 +++++++++ templates/flavors/k3s/secret.yaml | 50 ++++++++++++++++++++ 4 files changed, 140 insertions(+) create mode 100644 templates/flavors/k3s/k3sConfigTemplate.yaml create mode 100644 templates/flavors/k3s/k3sControlPlane.yaml create mode 100644 templates/flavors/k3s/kustomization.yaml create mode 100644 templates/flavors/k3s/secret.yaml diff --git a/templates/flavors/k3s/k3sConfigTemplate.yaml b/templates/flavors/k3s/k3sConfigTemplate.yaml new file mode 100644 index 000000000..b3d77b30a --- /dev/null +++ b/templates/flavors/k3s/k3sConfigTemplate.yaml @@ -0,0 +1,18 @@ +--- +apiVersion: bootstrap.cluster.x-k8s.io/v1beta1 +kind: KThreesConfigTemplate +metadata: + name: ${CLUSTER_NAME}-md-0 +spec: + template: + 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 \ No newline at end of file diff --git a/templates/flavors/k3s/k3sControlPlane.yaml b/templates/flavors/k3s/k3sControlPlane.yaml new file mode 100644 index 000000000..5916b65e7 --- /dev/null +++ b/templates/flavors/k3s/k3sControlPlane.yaml @@ -0,0 +1,50 @@ +--- +apiVersion: controlplane.cluster.x-k8s.io/v1beta1 +kind: KThreesControlPlane +metadata: + name: ${CLUSTER_NAME}-control-plane +spec: + infrastructureTemplate: + apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 + kind: LinodeMachineTemplate + name: ${CLUSTER_NAME}-control-plane + kthreesConfigSpec: + files: + - content: | + flannel-backend: none + disable-network-policy: true + owner: root:root + path: /etc/rancher/k3s/config.yaml.d/capi-config.yaml + - contentFrom: + secret: + key: cilium.yaml + name: linode-${CLUSTER_NAME}-crs-0 + owner: root:root + path: /var/lib/rancher/k3s/server/manifests/cilium.yaml + - contentFrom: + secret: + key: linode-ccm.yaml + name: linode-${CLUSTER_NAME}-crs-0 + owner: root:root + path: /var/lib/rancher/k3s/server/manifests/linode-ccm.yaml + - contentFrom: + secret: + key: linode-token-region.yaml + name: linode-${CLUSTER_NAME}-crs-0 + owner: root:root + path: /var/lib/rancher/k3s/server/manifests/linode-token-region.yaml + serverConfig: + disableComponents: + - servicelb + - 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 + replicas: ${CONTROL_PLANE_MACHINE_COUNT} + version: ${KUBERNETES_VERSION} \ No newline at end of file diff --git a/templates/flavors/k3s/kustomization.yaml b/templates/flavors/k3s/kustomization.yaml new file mode 100644 index 000000000..181a4be61 --- /dev/null +++ b/templates/flavors/k3s/kustomization.yaml @@ -0,0 +1,22 @@ +resources: + - ../base + - k3sControlPlane.yaml + - k3sConfigTemplate.yaml + - secret.yaml +patches: + - target: + group: cluster.x-k8s.io + version: v1beta1 + kind: Cluster + patch: |- + - op: replace + path: /spec/controlPlaneRef/kind + value: KThreesControlPlane + - target: + group: cluster.x-k8s.io + version: v1beta1 + kind: MachineDeployment + patch: |- + - op: replace + path: /spec/template/spec/bootstrap/configRef/kind + value: KThreesConfigTemplate \ No newline at end of file diff --git a/templates/flavors/k3s/secret.yaml b/templates/flavors/k3s/secret.yaml new file mode 100644 index 000000000..07522ec53 --- /dev/null +++ b/templates/flavors/k3s/secret.yaml @@ -0,0 +1,50 @@ +--- +apiVersion: v1 +kind: Secret +metadata: + name: linode-${CLUSTER_NAME}-crs-0 +stringData: + linode-token-region.yaml: |- + kind: Secret + apiVersion: v1 + metadata: + name: linode-token-region + namespace: kube-system + stringData: + apiToken: ${LINODE_TOKEN} + region: ${LINODE_REGION} + cilium.yaml: |- + apiVersion: helm.cattle.io/v1 + kind: HelmChart + metadata: + namespace: kube-system + name: cilium + spec: + targetNamespace: kube-system + version: v1.15.0 + chart: cilium + repo: https://helm.cilium.io/ + bootstrap: true + valuesContent: |- + hubble: + relay: + enabled: true + ui: + enabled: true + linode-ccm.yaml: |- + apiVersion: helm.cattle.io/v1 + kind: HelmChart + metadata: + namespace: kube-system + name: ccm-linode + spec: + targetNamespace: kube-system + version: v0.3.24 + chart: ccm-linode + repo: https://linode.github.io/linode-cloud-controller-manager/ + bootstrap: true + valuesContent: |- + secretRef: + name: "linode-token-region" + nodeSelector: + node-role.kubernetes.io/control-plane: "true" \ No newline at end of file