diff --git a/.gitignore b/.gitignore index 37ee674bd..dbd2a29c3 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,5 @@ kubeconfig* .devbox/* docs/book release/* +templates/cluster-template*.yaml +infrastructure-linode/* diff --git a/Makefile b/Makefile index fbbd06fda..b0b3a7cd1 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,6 @@ REGISTRY ?= docker.io/linode IMAGE_NAME ?= cluster-api-provider-linode CONTROLLER_IMAGE ?= $(REGISTRY)/$(IMAGE_NAME) -TAG ?= dev # ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary. ENVTEST_K8S_VERSION = 1.28.0 OS=$(shell uname -s | tr '[:upper:]' '[:lower:]') @@ -12,7 +11,7 @@ ARCH_SHORT := amd64 else ifeq ($(ARCH_SHORT),aarch64) ARCH_SHORT := arm64 endif -VERSION ?= $(shell git describe --tags --dirty=-dev) +VERSION ?= $(shell git describe --always --tag --dirty=-dev) BUILD_ARGS := --build-arg VERSION=$(VERSION) # Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) ifeq (,$(shell go env GOBIN)) @@ -73,6 +72,10 @@ manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and Cust generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations. $(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..." +.PHONY: generate-flavors ## Generate template flavors. +generate-flavors: $(KUSTOMIZE) + ./hack/generate-flavors.sh + ## -------------------------------------- ## Development ## -------------------------------------- @@ -135,20 +138,16 @@ _e2etest: manifests generate _e2etest-infra build: manifests generate fmt vet ## Build manager binary. go build -ldflags="-X github.com/linode/cluster-api-provider-linode/version.version=$(VERSION)" -o bin/manager cmd/main.go -.PHONY: run -run: manifests generate fmt vet ## Run a controller from your host. - go run ./cmd/main.go - # If you wish to build the manager image targeting other platforms you can use the --platform flag. # (i.e. docker build --platform linux/arm64). However, you must enable docker buildKit for it. # More info: https://docs.docker.com/develop/develop-images/build_enhancements/ .PHONY: docker-build docker-build: ## Build docker image with the manager. - $(CONTAINER_TOOL) build $(BUILD_ARGS) . -t $(CONTROLLER_IMAGE):$(TAG) + $(CONTAINER_TOOL) build $(BUILD_ARGS) . -t $(CONTROLLER_IMAGE):$(VERSION) .PHONY: docker-push docker-push: ## Push docker image with the manager. - $(CONTAINER_TOOL) push $(CONTROLLER_IMAGE):$(TAG) + $(CONTAINER_TOOL) push $(CONTROLLER_IMAGE):$(VERSION) # PLATFORMS defines the target platforms for the manager image be built to provide support to multiple # architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to: @@ -163,7 +162,7 @@ docker-buildx: ## Build and push docker image for the manager for cross-platform sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross - $(CONTAINER_TOOL) buildx create --name project-v3-builder $(CONTAINER_TOOL) buildx use project-v3-builder - - $(CONTAINER_TOOL) buildx build $(BUILD_ARGS) --push --platform=$(PLATFORMS) --tag $(CONTROLLER_IMAGE):$(TAG) -f Dockerfile.cross . + - $(CONTAINER_TOOL) buildx build $(BUILD_ARGS) --push --platform=$(PLATFORMS) --tag $(CONTROLLER_IMAGE):$(VERSION) -f Dockerfile.cross . - $(CONTAINER_TOOL) buildx rm project-v3-builder rm Dockerfile.cross @@ -190,20 +189,34 @@ tilt-cluster: ctlptl tilt kind clusterctl ##@ Release: RELEASE_DIR ?= release -RELEASE_TAG ?= $(shell git describe --abbrev=0 2>/dev/null) + +.PHONY: release +release: $(KUSTOMIZE) clean-release set-manifest-image release-manifests generate-flavors release-templates release-metadata clean-release-git + +$(RELEASE_DIR): + mkdir -p $(RELEASE_DIR)/ + +.PHONY: release-metadata +release-metadata: $(RELEASE_DIR) + cp metadata.yaml $(RELEASE_DIR)/metadata.yaml + +.PHONY: release-templates +release-templates: $(RELEASE_DIR) + mv templates/cluster-template* $(RELEASE_DIR)/ + mv templates/clusterclass* $(RELEASE_DIR)/ .PHONY: set-manifest-image set-manifest-image: ## Update kustomize image patch file for default resource. - sed -i'' -e 's@image: .*@image: '"${MANIFEST_IMG}:${MANIFEST_TAG}"'@' ./config/default/manager_image_patch.yaml + sed -i'' -e 's@image: .*@image: '"$(REGISTRY)/$(IMAGE_NAME):$(VERSION)"'@' ./config/default/manager_image_patch.yaml -.PHONY: release -release: $(KUSTOMIZE) - rm -rf $(RELEASE_DIR) - mkdir -p $(RELEASE_DIR)/ - $(MAKE) set-manifest-image MANIFEST_IMG=$(REGISTRY)/$(IMAGE_NAME) MANIFEST_TAG=$(RELEASE_TAG) +.PHONY: release-manifests +release-manifests: $(KUSTOMIZE) $(RELEASE_DIR) $(KUSTOMIZE) build config/default > $(RELEASE_DIR)/infrastructure-components.yaml - cp templates/cluster-template* $(RELEASE_DIR)/ - cp metadata.yaml $(RELEASE_DIR)/metadata.yaml + +.PHONY: local-release +local-release: + RELEASE_DIR=infrastructure-linode/0.0.0 $(MAKE) release + $(MAKE) clean-release-git ## -------------------------------------- ## Cleanup @@ -215,6 +228,14 @@ release: $(KUSTOMIZE) clean: rm -rf $(LOCALBIN) +.PHONY: clean-release-git +clean-release-git: ## Restores the git files usually modified during a release + git restore config/default/*manager_image_patch.yaml + +.PHONY: clean-release +clean-release: clean-release-git + rm -rf $(RELEASE_DIR) + ## -------------------------------------- ## Build Dependencies ## -------------------------------------- diff --git a/Tiltfile b/Tiltfile index dd82106ed..7aeebb361 100644 --- a/Tiltfile +++ b/Tiltfile @@ -9,7 +9,7 @@ docker_build( local_resource( 'capi-controller-manager', - cmd='EXP_CLUSTER_RESOURCE_SET=true clusterctl init --addon helm', + cmd='EXP_CLUSTER_RESOURCE_SET=true CLUSTER_TOPOLOGY=true clusterctl init --addon helm', ) manager_yaml = decode_yaml_stream(kustomize("config/default")) diff --git a/docs/src/developers/development.md b/docs/src/developers/development.md index ab5cb2317..5ef40a54e 100644 --- a/docs/src/developers/development.md +++ b/docs/src/developers/development.md @@ -7,16 +7,16 @@ - [Setting up](#setting-up) - [Base requirements](#base-requirements) - [Clone the source code](#clone-the-source-code) + - [Enable git hooks](#enable-git-hooks) + - [Set up devbox](#recommended-set-up-devbox) - [Get familiar with basic concepts](#get-familiar-with-basic-concepts) - [Developing](#developing) - - [Enable git hooks](#enable-git-hooks) - - [Setting up the environment](#setting-up-the-environment) - - [Using devbox](#using-devbox) - - [Tilt Requirements](#tilt-requirements) - [Using Tilt](#using-tilt) - [Deploying a workload cluster](#deploying-a-workload-cluster) - [Customizing the cluster deployment](#customizing-the-cluster-deployment) - [Creating the workload cluster](#creating-the-workload-cluster) + - [Using the default flavor](#using-the-default-flavor) + - [Using ClusterClass (alpha)](#using-clusterclass) - [Cleaning up the workload cluster](#cleaning-up-the-workload-cluster) - [Automated Testing](#automated-testing) - [E2E Testing](#e2e-testing) @@ -27,60 +27,40 @@ ### Base requirements +```admonish warning +Ensure you have your `LINODE_TOKEN` set as outlined in the +[getting started prerequisites](../topics/getting-started.md#Prerequisites) section. +``` + There are no requirements since development dependencies are fetched as needed via the make targets, but a recommendation is to [install Devbox](https://jetpack.io/devbox/docs/installing_devbox/) ### Clone the source code -```shell +```sh git clone https://github.com/linode/cluster-api-provider-linode cd cluster-api-provider-linode ``` -### Get familiar with basic concepts - -This provider is based on the [Cluster API project](https://github.com/kubernetes-sigs/cluster-api). -It's recommended to familiarize yourself with Cluster API resources, concepts, and conventions -outlined in the [Cluster API Book](https://cluster-api.sigs.k8s.io/). - -## Developing - -This repository uses [Go Modules](https://github.com/golang/go/wiki/Modules) -to track and vendor dependencies. - -To pin a new dependency, run: -```bash -go get @ -``` - ### Enable git hooks To enable automatic code validation on code push, execute the following commands: -```bash +```sh PATH="$PWD/bin:$PATH" make husky && husky install ``` If you would like to temporarily disable git hook, set `SKIP_GIT_PUSH_HOOK` value: -```bash +```sh SKIP_GIT_PUSH_HOOK=1 git push ``` -### Setting up the environment - -```admonish warning -Ensure you have your `LINODE_TOKEN` set as outlined in the -[getting started prerequisites](../topics/getting-started.md#Prerequisites) section. -``` +### [Recommended] Set up devbox -All development dependencies should be taken care of via Devbox and/or make target dependencies. - -#### Using devbox - -1. Install dependent packages in your project - ```shell +1. Install dependent packages in your project + ```sh devbox install ``` @@ -89,18 +69,35 @@ All development dependencies should be taken care of via Devbox and/or make targ ``` 2. Use devbox environment - ```shell + ```sh devbox shell ``` -From this point you can use the devbox shell like a regular shell. +From this point you can use the devbox shell like a regular shell. The rest of the guide assumes a devbox shell is used, but the make target dependencies will install any missing dependencies if needed when running -outside of a devbox shell. +outside a devbox shell. + +### Get familiar with basic concepts + +This provider is based on the [Cluster API project](https://github.com/kubernetes-sigs/cluster-api). +It's recommended to familiarize yourself with Cluster API resources, concepts, and conventions +outlined in the [Cluster API Book](https://cluster-api.sigs.k8s.io/). + +## Developing + +This repository uses [Go Modules](https://github.com/golang/go/wiki/Modules) +to track and vendor dependencies. + +To pin a new dependency, run: +```sh +go get @ +``` + ### Using tilt To build a kind cluster and start Tilt, simply run: -```shell +```sh make tilt-cluster ``` @@ -109,7 +106,7 @@ Once your kind management cluster is up and running, you can To tear down the tilt-cluster, run -```shell +```sh kind delete cluster --name tilt ``` @@ -117,11 +114,39 @@ kind delete cluster --name tilt After your kind management cluster is up and running with Tilt, you should be ready to deploy your first cluster. +#### Generating the cluster templates + +For local development, templates should be generated via: + +```sh +make local-release +``` + +This creates `infrastructure-linode/0.0.0/` with all the cluster templates: + +```sh +infrastructure-linode/0.0.0 +├── cluster-template-kubeadm-clusterclass.yaml +├── cluster-template.yaml +├── infrastructure-components.yaml +└── metadata.yaml +``` + +This can then be used with `clusterctl` by adding the following to `~/.clusterctl/cluster-api.yaml` +(assuming the repo exists in the `$HOME` directory): + +``` +providers: + - name: linode + url: ${HOME}/cluster-api-provider-linode/infrastructure-linode/0.0.0/infrastructure-components.yaml + type: InfrastructureProvider +``` + #### Customizing the cluster deployment Here is a list of required configuration parameters: -```bash +```sh # Cluster settings export CLUSTER_NAME=capl-cluster export KUBERNETES_VERSION=v1.29.1 @@ -137,30 +162,46 @@ export LINODE_MACHINE_TYPE=g6-standard-2 You can also use `clusterctl generate` to see which variables need to be set: ``` -clusterctl generate cluster $CLUSTER_NAME --from ./templates/cluster-template.yaml --list-variables +clusterctl generate cluster $CLUSTER_NAME --infrastructure linode:0.0.0 [--flavor ] --list-variables ``` ~~~ -```admonish warning -Please note the templates require the use of `clusterctl generate` to substitute the environment variables properly. -``` - #### Creating the workload cluster +##### Using the default flavor + Once you have all the necessary environment variables set, -you can deploy a workload cluster with the following command: +you can deploy a workload cluster with the default flavor: -```shell +```sh clusterctl generate cluster $CLUSTER_NAME \ --kubernetes-version v1.29.1 \ - --from templates/cluster-template.yaml \ + --infrastructure linode:0.0.0 \ | kubectl apply -f - ``` This will provision the cluster with the CNI defaulted to [cilium](../topics/addons.md#cilium) and the [linode-ccm](../topics/addons.md#ccm) installed. +##### Using ClusterClass (alpha) + +~~~admonish success title="" +ClusterClass experimental feature is enabled by default in the KIND management cluster +created via `make tilt-cluster` +~~~ + +You can use the `clusterclass` flavor to create a workload cluster as well, assuming the +management cluster has the [ClusterTopology feature gate set](https://cluster-api.sigs.k8s.io/tasks/experimental-features/cluster-class/): + +```sh +clusterctl generate cluster $CLUSTER_NAME \ + --kubernetes-version v1.29.1 \ + --infrastructure linode:0.0.0 \ + --flavor kubeadm-clusterclass \ + | kubectl apply -f - +``` + ```admonish question title="" For any issues, please refer to the [troubleshooting guide](../topics/troubleshooting.md). ``` @@ -169,7 +210,7 @@ For any issues, please refer to the [troubleshooting guide](../topics/troublesho To delete the cluster, simply run: -```bash +```sh kubectl delete cluster $CLUSTER_NAME ``` @@ -182,7 +223,7 @@ For any issues, please refer to the [troubleshooting guide](../topics/troublesho #### E2E Testing To run E2E locally run: -```bash +```sh make e2etest ``` diff --git a/hack/generate-flavors.sh b/hack/generate-flavors.sh new file mode 100755 index 000000000..38c7c25f0 --- /dev/null +++ b/hack/generate-flavors.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +set -euo pipefail + +REPO_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. +FLAVORS_DIR="${REPO_ROOT}/templates/flavors" + +for name in $(find "${FLAVORS_DIR}/"* -maxdepth 0 -type d -print0 | xargs -0 -I {} basename {} | grep -v base); do + # clusterctl expects clusterclass not have the "cluster-template" prefix + # except for the actual cluster template using the clusterclass + if [[ "$name" == clusterclass* ]]; then + kustomize build "${FLAVORS_DIR}/${name}" > "${REPO_ROOT}/templates/${name}.yaml" + cp "${FLAVORS_DIR}/${name}/cluster-template.yaml" "${REPO_ROOT}/templates/cluster-template-${name}.yaml" + else + kustomize build "${FLAVORS_DIR}/${name}" > "${REPO_ROOT}/templates/cluster-template-${name}.yaml" + fi +done + +# move the default template to the default file expected by clusterctl +mv "${REPO_ROOT}/templates/cluster-template-default.yaml" "${REPO_ROOT}/templates/cluster-template.yaml" diff --git a/templates/addons/cilium/cilium.yaml b/templates/addons/cilium/cilium.yaml new file mode 100644 index 000000000..5eb267d1d --- /dev/null +++ b/templates/addons/cilium/cilium.yaml @@ -0,0 +1,22 @@ +apiVersion: addons.cluster.x-k8s.io/v1alpha1 +kind: HelmChartProxy +metadata: + name: cilium +spec: + clusterSelector: + matchLabels: + cni: cilium + repoURL: https://helm.cilium.io/ + chartName: cilium + namespace: kube-system + version: ${CILIUM_VERSION:=1.15.0} + options: + waitForJobs: true + wait: true + timeout: 5m + valuesTemplate: | + hubble: + relay: + enabled: true + ui: + enabled: true diff --git a/templates/addons/cilium/kustomization.yaml b/templates/addons/cilium/kustomization.yaml new file mode 100644 index 000000000..07edafad1 --- /dev/null +++ b/templates/addons/cilium/kustomization.yaml @@ -0,0 +1,4 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: + - cilium.yaml diff --git a/templates/addons/cluster-resource-set/kustomization.yaml b/templates/addons/cluster-resource-set/kustomization.yaml new file mode 100644 index 000000000..97a816adb --- /dev/null +++ b/templates/addons/cluster-resource-set/kustomization.yaml @@ -0,0 +1,5 @@ + +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: + - secret.yaml diff --git a/templates/addons/cluster-resource-set/secret.yaml b/templates/addons/cluster-resource-set/secret.yaml new file mode 100644 index 000000000..554fc1ea9 --- /dev/null +++ b/templates/addons/cluster-resource-set/secret.yaml @@ -0,0 +1,29 @@ +apiVersion: v1 +kind: Secret +type: addons.cluster.x-k8s.io/resource-set +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} +--- +apiVersion: addons.cluster.x-k8s.io/v1beta1 +kind: ClusterResourceSet +metadata: + name: ${CLUSTER_NAME}-crs-0 +spec: + clusterSelector: + matchLabels: + crs: ${CLUSTER_NAME}-crs + resources: + - kind: Secret + name: linode-${CLUSTER_NAME}-crs-0 + strategy: ApplyOnce +--- diff --git a/templates/addons/linode-blockstorage-csi-driver/kustomization.yaml b/templates/addons/linode-blockstorage-csi-driver/kustomization.yaml new file mode 100644 index 000000000..02d14e4ac --- /dev/null +++ b/templates/addons/linode-blockstorage-csi-driver/kustomization.yaml @@ -0,0 +1,4 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: + - linode-bs-csi.yaml diff --git a/templates/addons/linode-blockstorage-csi-driver-helm.yaml b/templates/addons/linode-blockstorage-csi-driver/linode-bs-csi.yaml similarity index 100% rename from templates/addons/linode-blockstorage-csi-driver-helm.yaml rename to templates/addons/linode-blockstorage-csi-driver/linode-bs-csi.yaml diff --git a/templates/addons/provider-linode/kustomization.yaml b/templates/addons/provider-linode/kustomization.yaml new file mode 100644 index 000000000..8adc23586 --- /dev/null +++ b/templates/addons/provider-linode/kustomization.yaml @@ -0,0 +1,4 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: + - linode-ccm.yaml diff --git a/templates/addons/provider-linode/linode-ccm.yaml b/templates/addons/provider-linode/linode-ccm.yaml new file mode 100644 index 000000000..dd2839fa4 --- /dev/null +++ b/templates/addons/provider-linode/linode-ccm.yaml @@ -0,0 +1,21 @@ +apiVersion: addons.cluster.x-k8s.io/v1alpha1 +kind: HelmChartProxy +metadata: + name: linode-cloud-controller-manager +spec: + clusterSelector: + matchLabels: + ccm: linode + repoURL: https://linode.github.io/linode-cloud-controller-manager/ + chartName: ccm-linode + namespace: kube-system + version: ${LINODE_CCM_VERSION:=v0.3.24} + options: + waitForJobs: true + wait: true + timeout: 5m + valuesTemplate: | + secretRef: + name: "linode-token-region" + image: + pullPolicy: IfNotPresent diff --git a/templates/cluster-template.yaml b/templates/cluster-template.yaml deleted file mode 100644 index 706bffb92..000000000 --- a/templates/cluster-template.yaml +++ /dev/null @@ -1,288 +0,0 @@ -apiVersion: cluster.x-k8s.io/v1beta1 -kind: Cluster -metadata: - name: ${CLUSTER_NAME} - labels: - cni: cilium - ccm: linode - crs: ${CLUSTER_NAME}-crs -spec: - clusterNetwork: - pods: - cidrBlocks: - - 192.168.128.0/17 - controlPlaneRef: - apiVersion: controlplane.cluster.x-k8s.io/v1beta1 - kind: KubeadmControlPlane - name: ${CLUSTER_NAME}-control-plane - infrastructureRef: - apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 - kind: LinodeCluster - name: ${CLUSTER_NAME} ---- -apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 -kind: LinodeCluster -metadata: - name: ${CLUSTER_NAME} -spec: - region: ${LINODE_REGION} ---- -kind: KubeadmControlPlane -apiVersion: controlplane.cluster.x-k8s.io/v1beta1 -metadata: - name: ${CLUSTER_NAME}-control-plane -spec: - replicas: ${CONTROL_PLANE_MACHINE_COUNT} - machineTemplate: - infrastructureRef: - kind: LinodeMachineTemplate - apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 - name: ${CLUSTER_NAME}-control-plane - kubeadmConfigSpec: - files: - - path: /etc/containerd/config.toml - contentFrom: - secret: - name: common-init-files - key: containerd-config.toml - - path: /etc/modules-load.d/k8s.conf - contentFrom: - secret: - name: common-init-files - key: k8s-modules.conf - - path: /etc/sysctl.d/k8s.conf - contentFrom: - secret: - name: common-init-files - key: sysctl-k8s.conf - - path: /kubeadm-pre-init.sh - contentFrom: - secret: - name: common-init-files - key: kubeadm-pre-init.sh - permissions: "0500" - preKubeadmCommands: - - /kubeadm-pre-init.sh '{{ ds.meta_data.label }}' ${KUBERNETES_VERSION} - clusterConfiguration: - apiServer: - extraArgs: - cloud-provider: external - controllerManager: - extraArgs: - cloud-provider: external - initConfiguration: - 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}" ---- -kind: LinodeMachineTemplate -apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 -metadata: - name: ${CLUSTER_NAME}-control-plane -spec: - template: - spec: - image: ${LINODE_OS:="linode/ubuntu22.04"} - type: ${LINODE_CONTROL_PLANE_MACHINE_TYPE} - region: ${LINODE_REGION} - authorizedKeys: - # uncomment to include your ssh key in linode provisioning - # - ${LINODE_SSH_PUBKEY:=""} ---- -apiVersion: cluster.x-k8s.io/v1beta1 -kind: MachineDeployment -metadata: - name: ${CLUSTER_NAME}-md-0 -spec: - clusterName: ${CLUSTER_NAME} - replicas: ${WORKER_MACHINE_COUNT} - selector: - matchLabels: - template: - spec: - clusterName: ${CLUSTER_NAME} - version: "${KUBERNETES_VERSION}" - bootstrap: - configRef: - name: ${CLUSTER_NAME}-md-0 - apiVersion: bootstrap.cluster.x-k8s.io/v1beta1 - kind: KubeadmConfigTemplate - infrastructureRef: - name: ${CLUSTER_NAME}-md-0 - apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 - kind: LinodeMachineTemplate ---- -apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 -kind: LinodeMachineTemplate -metadata: - name: ${CLUSTER_NAME}-md-0 -spec: - template: - spec: - image: ${LINODE_OS:="linode/ubuntu22.04"} - type: ${LINODE_MACHINE_TYPE} - region: ${LINODE_REGION} - authorizedKeys: - # uncomment to include your ssh key in linode provisioning - # - ${LINODE_SSH_PUBKEY:=""} ---- -apiVersion: bootstrap.cluster.x-k8s.io/v1beta1 -kind: KubeadmConfigTemplate -metadata: - name: ${CLUSTER_NAME}-md-0 -spec: - template: - spec: - files: - - path: /etc/containerd/config.toml - contentFrom: - secret: - name: common-init-files - key: containerd-config.toml - - path: /etc/modules-load.d/k8s.conf - contentFrom: - secret: - name: common-init-files - key: k8s-modules.conf - - path: /etc/sysctl.d/k8s.conf - contentFrom: - secret: - name: common-init-files - key: sysctl-k8s.conf - - path: /kubeadm-pre-init.sh - contentFrom: - secret: - name: common-init-files - key: kubeadm-pre-init.sh - permissions: "0500" - preKubeadmCommands: - - /kubeadm-pre-init.sh '{{ ds.meta_data.label }}' ${KUBERNETES_VERSION} - joinConfiguration: - nodeRegistration: - kubeletExtraArgs: - cloud-provider: external - provider-id: 'linode://{{ ds.meta_data.id }}' - name: '{{ ds.meta_data.label }}' ---- -apiVersion: v1 -kind: Secret -metadata: - name: common-init-files -stringData: - containerd-config.toml: | - version = 2 - imports = ["/etc/containerd/conf.d/*.toml"] - [plugins] - [plugins."io.containerd.grpc.v1.cri"] - sandbox_image = "registry.k8s.io/pause:3.9" - [plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc] - runtime_type = "io.containerd.runc.v2" - [plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc.options] - SystemdCgroup = true - k8s-modules.conf: | - overlay - br_netfilter - sysctl-k8s.conf: | - net.bridge.bridge-nf-call-iptables = 1 - net.bridge.bridge-nf-call-ip6tables = 1 - net.ipv4.ip_forward = 1 - kubeadm-pre-init.sh: | - #!/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]} - 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 - apt-get update -y - apt-get install -y kubelet=$PATCH_VERSION* kubeadm=$PATCH_VERSION* kubectl=$PATCH_VERSION* containerd - apt-mark hold kubelet kubeadm kubectl containerd - modprobe overlay - modprobe br_netfilter - sysctl --system - sed -i '/swap/d' /etc/fstab - swapoff -a ---- -apiVersion: v1 -kind: Secret -type: addons.cluster.x-k8s.io/resource-set -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} ---- -apiVersion: addons.cluster.x-k8s.io/v1beta1 -kind: ClusterResourceSet -metadata: - name: ${CLUSTER_NAME}-crs-0 -spec: - clusterSelector: - matchLabels: - crs: ${CLUSTER_NAME}-crs - resources: - - kind: Secret - name: linode-${CLUSTER_NAME}-crs-0 - strategy: ApplyOnce ---- -apiVersion: addons.cluster.x-k8s.io/v1alpha1 -kind: HelmChartProxy -metadata: - name: cilium -spec: - clusterSelector: - matchLabels: - cni: cilium - repoURL: https://helm.cilium.io/ - chartName: cilium - version: 1.15.0 - options: - waitForJobs: true - wait: true - timeout: 5m - valuesTemplate: | - hubble: - relay: - enabled: true - ui: - enabled: true ---- -apiVersion: addons.cluster.x-k8s.io/v1alpha1 -kind: HelmChartProxy -metadata: - name: linode-cloud-controller-manager -spec: - clusterSelector: - matchLabels: - ccm: linode - repoURL: https://linode.github.io/linode-cloud-controller-manager/ - chartName: ccm-linode - namespace: kube-system - version: v0.3.24 - options: - waitForJobs: true - wait: true - timeout: 5m - valuesTemplate: | - secretRef: - name: "linode-token-region" - image: - pullPolicy: IfNotPresent diff --git a/templates/common-init-files/kustomization.yaml b/templates/common-init-files/kustomization.yaml new file mode 100644 index 000000000..82ec21000 --- /dev/null +++ b/templates/common-init-files/kustomization.yaml @@ -0,0 +1,3 @@ +namespace: default +resources: + - secret.yaml diff --git a/templates/common-init-files/secret.yaml b/templates/common-init-files/secret.yaml new file mode 100644 index 000000000..e2b3a7827 --- /dev/null +++ b/templates/common-init-files/secret.yaml @@ -0,0 +1,41 @@ +apiVersion: v1 +kind: Secret +metadata: + name: common-init-files +stringData: + containerd-config.toml: | + version = 2 + imports = ["/etc/containerd/conf.d/*.toml"] + [plugins] + [plugins."io.containerd.grpc.v1.cri"] + sandbox_image = "registry.k8s.io/pause:3.9" + [plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc] + runtime_type = "io.containerd.runc.v2" + [plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc.options] + SystemdCgroup = true + k8s-modules.conf: | + overlay + br_netfilter + sysctl-k8s.conf: | + net.bridge.bridge-nf-call-iptables = 1 + net.bridge.bridge-nf-call-ip6tables = 1 + net.ipv4.ip_forward = 1 + kubeadm-pre-init.sh: | + #!/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]} + 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 + apt-get update -y + apt-get install -y kubelet=$PATCH_VERSION* kubeadm=$PATCH_VERSION* kubectl=$PATCH_VERSION* containerd + apt-mark hold kubelet kubeadm kubectl containerd + modprobe overlay + modprobe br_netfilter + sysctl --system + sed -i '/swap/d' /etc/fstab + swapoff -a + diff --git a/templates/flavors/README.md b/templates/flavors/README.md new file mode 100644 index 000000000..c297af5a1 --- /dev/null +++ b/templates/flavors/README.md @@ -0,0 +1,20 @@ +# Flavors + +In `clusterctl` the infrastructure provider authors can provide different types +of cluster templates referred to as "flavors". You can use the `--flavor` flag +to specify which flavor to use for a cluster, e.g: + +```shell +clusterctl generate cluster test-cluster --flavor clusterclass +``` + +To use the default flavor, omit the `--flavor` flag. + +See the [`clusterctl` flavors docs](https://cluster-api.sigs.k8s.io/clusterctl/commands/generate-cluster.html#flavors) for more information. + +This directory contains each of the flavors for CAPL. Each directory besides `base` will be used to +create a flavor by running `kustomize build` on the directory. The name of the directory will be +appended to the end of the cluster-template.yaml, e.g cluster-template-{directory-name}.yaml. That +flavor can be used by specifying `--flavor {directory-name}`. + +To generate all CAPL flavors, run `make generate-flavors`. diff --git a/templates/flavors/base/cluster-template.yaml b/templates/flavors/base/cluster-template.yaml new file mode 100644 index 000000000..0c9fa6a14 --- /dev/null +++ b/templates/flavors/base/cluster-template.yaml @@ -0,0 +1,99 @@ +apiVersion: cluster.x-k8s.io/v1beta1 +kind: Cluster +metadata: + name: ${CLUSTER_NAME} + labels: + cni: cilium + ccm: linode + crs: ${CLUSTER_NAME}-crs +spec: + clusterNetwork: + pods: + cidrBlocks: + - 192.168.128.0/17 + controlPlaneRef: + apiVersion: controlplane.cluster.x-k8s.io/v1beta1 + kind: KubeadmControlPlane + name: ${CLUSTER_NAME}-control-plane + infrastructureRef: + apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 + kind: LinodeCluster + name: ${CLUSTER_NAME} +--- +apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 +kind: LinodeCluster +metadata: + name: ${CLUSTER_NAME} +spec: + region: ${LINODE_REGION} +--- +kind: KubeadmControlPlane +apiVersion: controlplane.cluster.x-k8s.io/v1beta1 +metadata: + name: ${CLUSTER_NAME}-control-plane +spec: + replicas: ${CONTROL_PLANE_MACHINE_COUNT} + machineTemplate: + infrastructureRef: + kind: LinodeMachineTemplate + apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 + name: ${CLUSTER_NAME}-control-plane + kubeadmConfigSpec: + files: + - path: /etc/containerd/config.toml + contentFrom: + secret: + name: common-init-files + key: containerd-config.toml + - path: /etc/modules-load.d/k8s.conf + contentFrom: + secret: + name: common-init-files + key: k8s-modules.conf + - path: /etc/sysctl.d/k8s.conf + contentFrom: + secret: + name: common-init-files + key: sysctl-k8s.conf + - path: /kubeadm-pre-init.sh + contentFrom: + secret: + name: common-init-files + key: kubeadm-pre-init.sh + permissions: "0500" + preKubeadmCommands: + - /kubeadm-pre-init.sh '{{ ds.meta_data.label }}' "${KUBERNETES_VERSION}" + clusterConfiguration: + apiServer: + extraArgs: + cloud-provider: external + controllerManager: + extraArgs: + cloud-provider: external + initConfiguration: + 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}" +--- +kind: LinodeMachineTemplate +apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 +metadata: + name: ${CLUSTER_NAME}-control-plane +spec: + template: + spec: + image: ${LINODE_OS:="linode/ubuntu22.04"} + type: ${LINODE_CONTROL_PLANE_MACHINE_TYPE} + region: ${LINODE_REGION} + authorizedKeys: + # uncomment to include your ssh key in linode provisioning + # - ${LINODE_SSH_PUBKEY:=""} diff --git a/templates/flavors/base/kustomization.yaml b/templates/flavors/base/kustomization.yaml new file mode 100644 index 000000000..d5709d2ab --- /dev/null +++ b/templates/flavors/base/kustomization.yaml @@ -0,0 +1,4 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: + - cluster-template.yaml diff --git a/templates/flavors/clusterclass-kubeadm/cluster-template.yaml b/templates/flavors/clusterclass-kubeadm/cluster-template.yaml new file mode 100644 index 000000000..4aef17cef --- /dev/null +++ b/templates/flavors/clusterclass-kubeadm/cluster-template.yaml @@ -0,0 +1,30 @@ +apiVersion: cluster.x-k8s.io/v1beta1 +kind: Cluster +metadata: + name: ${CLUSTER_NAME} + labels: + cni: cilium + ccm: linode + crs: ${CLUSTER_NAME}-crs +spec: + clusterNetwork: + pods: + cidrBlocks: + - 192.168.128.0/17 + topology: + class: kubeadm + version: ${KUBERNETES_VERSION} + variables: + - name: region + value: ${LINODE_REGION} + - name: controlPlaneMachineType + value: ${LINODE_CONTROL_PLANE_MACHINE_TYPE} + - name: workerMachineType + value: ${LINODE_MACHINE_TYPE} + controlPlane: + replicas: ${CONTROL_PLANE_MACHINE_COUNT} + workers: + machineDeployments: + - class: default-worker + name: md-0 + replicas: ${WORKER_MACHINE_COUNT} diff --git a/templates/flavors/clusterclass-kubeadm/clusterclass.yaml b/templates/flavors/clusterclass-kubeadm/clusterclass.yaml new file mode 100644 index 000000000..68bdd2339 --- /dev/null +++ b/templates/flavors/clusterclass-kubeadm/clusterclass.yaml @@ -0,0 +1,144 @@ +apiVersion: cluster.x-k8s.io/v1beta1 +kind: ClusterClass +metadata: + name: kubeadm +spec: + controlPlane: + ref: + apiVersion: controlplane.cluster.x-k8s.io/v1beta1 + kind: KubeadmControlPlaneTemplate + name: kubeadm-control-plane + machineInfrastructure: + ref: + apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 + kind: LinodeMachineTemplate + name: kubeadm-control-plane + infrastructure: + ref: + apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 + kind: LinodeClusterTemplate + name: kubeadm + workers: + machineDeployments: + - class: default-worker + template: + bootstrap: + ref: + apiVersion: bootstrap.cluster.x-k8s.io/v1beta1 + kind: KubeadmConfigTemplate + name: kubeadm-worker + infrastructure: + ref: + apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 + kind: LinodeMachineTemplate + name: kubeadm-worker + variables: + - name: region + required: true + schema: + openAPIV3Schema: + type: string + default: us-ord + - name: controlPlaneMachineType + required: true + schema: + openAPIV3Schema: + type: string + default: g6-standard-2 + - name: workerMachineType + required: true + schema: + openAPIV3Schema: + type: string + default: g6-standard-2 + - name: osImage + required: true + schema: + openAPIV3Schema: + type: string + default: linode/ubuntu22.04 + patches: + - name: region + definitions: + - selector: + apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 + kind: LinodeClusterTemplate + matchResources: + infrastructureCluster: true + jsonPatches: + - op: add + path: /spec/template/spec/region + valueFrom: + variable: region + - selector: + apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 + kind: LinodeMachineTemplate + matchResources: + controlPlane: true + jsonPatches: + - op: replace + path: /spec/template/spec/region + valueFrom: + variable: region + - selector: + apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 + kind: LinodeMachineTemplate + matchResources: + machineDeploymentClass: + names: + - default-worker + jsonPatches: + - op: replace + path: /spec/template/spec/region + valueFrom: + variable: region + - name: controlPlaneMachineType + definitions: + - selector: + apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 + kind: LinodeMachineTemplate + matchResources: + controlPlane: true + jsonPatches: + - op: replace + path: /spec/template/spec/type + valueFrom: + variable: controlPlaneMachineType + - name: workerMachineType + definitions: + - selector: + apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 + kind: LinodeMachineTemplate + matchResources: + machineDeploymentClass: + names: + - default-worker + jsonPatches: + - op: replace + path: /spec/template/spec/type + valueFrom: + variable: workerMachineType + - name: osImage + definitions: + - selector: + apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 + kind: LinodeMachineTemplate + matchResources: + machineDeploymentClass: + names: + - default-worker + jsonPatches: + - op: replace + path: /spec/template/spec/image + valueFrom: + variable: osImage + - selector: + apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 + kind: LinodeMachineTemplate + matchResources: + controlPlane: true + jsonPatches: + - op: replace + path: /spec/template/spec/image + valueFrom: + variable: osImage diff --git a/templates/flavors/clusterclass-kubeadm/kubeadm-config-template.yaml b/templates/flavors/clusterclass-kubeadm/kubeadm-config-template.yaml new file mode 100644 index 000000000..c19aa3002 --- /dev/null +++ b/templates/flavors/clusterclass-kubeadm/kubeadm-config-template.yaml @@ -0,0 +1,37 @@ +apiVersion: bootstrap.cluster.x-k8s.io/v1beta1 +kind: KubeadmConfigTemplate +metadata: + name: kubeadm-worker +spec: + template: + spec: + files: + - path: /etc/containerd/config.toml + contentFrom: + secret: + name: common-init-files + key: containerd-config.toml + - path: /etc/modules-load.d/k8s.conf + contentFrom: + secret: + name: common-init-files + key: k8s-modules.conf + - path: /etc/sysctl.d/k8s.conf + contentFrom: + secret: + name: common-init-files + key: sysctl-k8s.conf + - path: /kubeadm-pre-init.sh + contentFrom: + secret: + name: common-init-files + key: kubeadm-pre-init.sh + permissions: "0500" + preKubeadmCommands: + - /kubeadm-pre-init.sh '{{ ds.meta_data.label }}' ${KUBERNETES_VERSION} + 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/kubeadm-controlplane-template.yaml b/templates/flavors/clusterclass-kubeadm/kubeadm-controlplane-template.yaml new file mode 100644 index 000000000..6f3f72dee --- /dev/null +++ b/templates/flavors/clusterclass-kubeadm/kubeadm-controlplane-template.yaml @@ -0,0 +1,51 @@ +kind: KubeadmControlPlaneTemplate +apiVersion: controlplane.cluster.x-k8s.io/v1beta1 +metadata: + name: kubeadm-control-plane +spec: + template: + spec: + kubeadmConfigSpec: + files: + - path: /etc/containerd/config.toml + contentFrom: + secret: + name: common-init-files + key: containerd-config.toml + - path: /etc/modules-load.d/k8s.conf + contentFrom: + secret: + name: common-init-files + key: k8s-modules.conf + - path: /etc/sysctl.d/k8s.conf + contentFrom: + secret: + name: common-init-files + key: sysctl-k8s.conf + - path: /kubeadm-pre-init.sh + contentFrom: + secret: + name: common-init-files + key: kubeadm-pre-init.sh + permissions: "0500" + preKubeadmCommands: + - /kubeadm-pre-init.sh '{{ ds.meta_data.label }}' "${KUBERNETES_VERSION}" + clusterConfiguration: + apiServer: + extraArgs: + cloud-provider: external + controllerManager: + extraArgs: + cloud-provider: external + initConfiguration: + 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/clusterclass-kubeadm/kustomization.yaml b/templates/flavors/clusterclass-kubeadm/kustomization.yaml new file mode 100644 index 000000000..3ead4f48f --- /dev/null +++ b/templates/flavors/clusterclass-kubeadm/kustomization.yaml @@ -0,0 +1,11 @@ +resources: + - clusterclass.yaml + - linode-cluster-template.yaml + - linode-machine-controlplane-template.yaml + - linode-machine-worker-template.yaml + - kubeadm-controlplane-template.yaml + - kubeadm-config-template.yaml + - ../../common-init-files + - ../../addons/cilium + - ../../addons/provider-linode + - ../../addons/cluster-resource-set diff --git a/templates/flavors/clusterclass-kubeadm/linode-cluster-template.yaml b/templates/flavors/clusterclass-kubeadm/linode-cluster-template.yaml new file mode 100644 index 000000000..1e3f6d74e --- /dev/null +++ b/templates/flavors/clusterclass-kubeadm/linode-cluster-template.yaml @@ -0,0 +1,9 @@ +apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 +kind: LinodeClusterTemplate +metadata: + name: kubeadm +spec: + template: + spec: + # region is a required field (OpenAPI schema). + region: REPLACEME diff --git a/templates/flavors/clusterclass-kubeadm/linode-machine-controlplane-template.yaml b/templates/flavors/clusterclass-kubeadm/linode-machine-controlplane-template.yaml new file mode 100644 index 000000000..89666c070 --- /dev/null +++ b/templates/flavors/clusterclass-kubeadm/linode-machine-controlplane-template.yaml @@ -0,0 +1,13 @@ +kind: LinodeMachineTemplate +apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 +metadata: + name: kubeadm-control-plane +spec: + template: + spec: + # image is a required field (OpenAPI schema). + image: REPLACEME + # type is a required field (OpenAPI schema). + type: REPLACEME + # region is a required field (OpenAPI schema). + region: REPLACEME diff --git a/templates/flavors/clusterclass-kubeadm/linode-machine-worker-template.yaml b/templates/flavors/clusterclass-kubeadm/linode-machine-worker-template.yaml new file mode 100644 index 000000000..10da62b09 --- /dev/null +++ b/templates/flavors/clusterclass-kubeadm/linode-machine-worker-template.yaml @@ -0,0 +1,13 @@ +apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 +kind: LinodeMachineTemplate +metadata: + name: kubeadm-worker +spec: + template: + spec: + # image is a required field (OpenAPI schema). + image: REPLACEME + # type is a required field (OpenAPI schema). + type: REPLACEME + # region is a required field (OpenAPI schema). + region: REPLACEME diff --git a/templates/flavors/default/kustomization.yaml b/templates/flavors/default/kustomization.yaml new file mode 100644 index 000000000..a02873200 --- /dev/null +++ b/templates/flavors/default/kustomization.yaml @@ -0,0 +1,7 @@ +resources: + - ../base + - machine-deployment.yaml + - ../../common-init-files + - ../../addons/cilium + - ../../addons/provider-linode + - ../../addons/cluster-resource-set diff --git a/templates/flavors/default/machine-deployment.yaml b/templates/flavors/default/machine-deployment.yaml new file mode 100644 index 000000000..22065cb52 --- /dev/null +++ b/templates/flavors/default/machine-deployment.yaml @@ -0,0 +1,74 @@ +apiVersion: cluster.x-k8s.io/v1beta1 +kind: MachineDeployment +metadata: + name: ${CLUSTER_NAME}-md-0 +spec: + clusterName: ${CLUSTER_NAME} + replicas: ${WORKER_MACHINE_COUNT} + selector: + matchLabels: + template: + spec: + clusterName: ${CLUSTER_NAME} + version: "${KUBERNETES_VERSION}" + bootstrap: + configRef: + name: ${CLUSTER_NAME}-md-0 + apiVersion: bootstrap.cluster.x-k8s.io/v1beta1 + kind: KubeadmConfigTemplate + infrastructureRef: + name: ${CLUSTER_NAME}-md-0 + apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 + kind: LinodeMachineTemplate +--- +apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 +kind: LinodeMachineTemplate +metadata: + name: ${CLUSTER_NAME}-md-0 +spec: + template: + spec: + image: ${LINODE_OS:="linode/ubuntu22.04"} + type: ${LINODE_MACHINE_TYPE} + region: ${LINODE_REGION} + authorizedKeys: + # uncomment to include your ssh key in linode provisioning + # - ${LINODE_SSH_PUBKEY:=""} +--- +apiVersion: bootstrap.cluster.x-k8s.io/v1beta1 +kind: KubeadmConfigTemplate +metadata: + name: ${CLUSTER_NAME}-md-0 +spec: + template: + spec: + files: + - path: /etc/containerd/config.toml + contentFrom: + secret: + name: common-init-files + key: containerd-config.toml + - path: /etc/modules-load.d/k8s.conf + contentFrom: + secret: + name: common-init-files + key: k8s-modules.conf + - path: /etc/sysctl.d/k8s.conf + contentFrom: + secret: + name: common-init-files + key: sysctl-k8s.conf + - path: /kubeadm-pre-init.sh + contentFrom: + secret: + name: common-init-files + key: kubeadm-pre-init.sh + permissions: "0500" + preKubeadmCommands: + - /kubeadm-pre-init.sh '{{ ds.meta_data.label }}' "${KUBERNETES_VERSION}" + joinConfiguration: + nodeRegistration: + kubeletExtraArgs: + cloud-provider: external + provider-id: 'linode://{{ ds.meta_data.id }}' + name: '{{ ds.meta_data.label }}'