rke2-cluster-templates

by FZJ ICE-1

Helm chartv9.1.0MITVerified publisher

RKE2 cluster template using Rancher Turtles (CAPI) for automated cluster provisioning.

About this chart

rke2 Cluster Templates Helm Chart

This chart uses the kubernetes Cluster API (CAPI) for creating downstream kubernetes cluster, with rke2 as kubernetes distribution.

Additional kubernetes distributions may be added in the future, should the need arise.

Recommendations

Hardware requirements

A single node should have at the minimum 2 CPUs and 4GB RAM.
Recommended would be 4 CPUs and 8GB RAM, which would roughly allow ~100 Pods per Node.
Check the rke2 requirements doc for additional information.

Rancher

While it shouldn't be necessary, using Rancher for simplifying the setup and management of clusters is recommended.

Requirements

Either use Rancher Turtles which is deployed together with or install the Cluster API Operator.

A deployment of all required CAPI Provider and additional details can be found here.
The required CAPI Provider for the Cluster are:

  • Addon: rancher-fleet
  • Bootstrap: rke2
  • Control Plane: rke2

The supported CAPI Provider for the Machines are:

Additional CAPI Provider implementations may be requested.

OpenStack

To use OpenStack as cloudprovider use the values-openstack.yaml file as reference.
It contains a minimal example of options that have to be defined and their corresponding defaults.

Additionally create secret with clouds.yaml as key and the OpenStack API information as value:

apiVersion: v1
kind: Secret
metadata:
  name: openstack-cloud-config  # same as "openstack.cloudSecretName"
  namespace: fleet-default
clouds.yaml:
  clouds:
    openstack:  # same as "openstack.cloudName"
      auth:
        auth_url: https://keystone:5000/v3
        application_credential_id: "..."
        application_credential_secret: "..."
      region_name: RegionOne
      auth_type: v3applicationcredential

If it is desired to make the Cluster accessible e.g. via SSH from the outside, it is possible to enable the creation of a Bastion Node with a floating IP (disabled by default).

Installing the Chart

[!important] :exclamation: Important
The clusterMembers cluster role template binding and the etcd-snapshot-sync cron job are only created with the second run of the template.
That is because the required management.cattle.io object of the cluster is automatically created after the initial setup and both need it to exist.

clusterProjects require an additional third run, because the ProjectRoleTemplateBinding can only be created when the Project field status.backingNamespace is populated after the second run (it also requires the management.cattle.io).
Attaching namespaces to a project is done in the downstream cluster via the field.cattle.io/projectId annotation.

Using Helm Install via Repository

Add the repository as described here.

# Install latest Version
helm repo update
helm upgrade -i -n fleet-default <cluster-name> ict-platform/rke2-cluster-templates -f values.yaml
# List available versions
helm search repo ict-platform --versions
# Install specific version
helm install -n fleet-default <cluster-name> ict-platform/rke2-cluster-templates --version <x.x.x> -f values.yaml

Using OCI Container Registry

# Show the default values
helm show values oci://jugit-registry.fz-juelich.de/iek-10/public/ict-platform/deployment/kubernetes/helm-charts/rke2-cluster-templates --version <x.x.x>
# Show the rendered manifests with your values
helm template -n vernemq vernemq oci://jugit-registry.fz-juelich.de/iek-10/public/ict-platform/deployment/kubernetes/helm-charts/rke2-cluster-templates --version <x.x.x> -f values.yaml
# Install
helm upgrade -i -n vernemq vernemq oci://jugit-registry.fz-juelich.de/iek-10/public/ict-platform/deployment/kubernetes/helm-charts/rke2-cluster-templates --version <x.x.x> -f values.yaml

Using Rancher

Follow the steps described here.
Clusters can than be added through the Cluster Management option in the rancher dashboard.

Cluster Deployment Status

Cluster info

kubectl -n fleet-default get clusters.cluster.x-k8s.io
kubectl -n fleet-default get clusters.management.cattle.io -o custom-columns="NAME:.metadata.name,CAPI_NAME:.metadata.labels.cluster-api\.cattle\.io/capi-cluster-owner"
kubectl -n default get clusters.provisioning.cattle.io

kubectl -n caprke2-system logs -l cluster.x-k8s.io/provider=control-plane-rke2 --tail=5
kubectl -n caprke2-system logs -l cluster.x-k8s.io/provider=bootstrap-rke2 --tail=5

Control Plane info

kubectl -n fleet-default get rke2controlplanes.controlplane.cluster.x-k8s.io
kubectl -n fleet-default get rke2configs.bootstrap.cluster.x-k8s.io

Worker Info

kubectl -n fleet-default get rke2configtemplates.bootstrap.cluster.x-k8s.io
kubectl -n fleet-default get machinedeployments.cluster.x-k8s.io
kubectl -n fleet-default get machinesets.cluster.x-k8s.io

Machine Info

kubectl get -n fleet-default machines.cluster.x-k8s.io

OpenStack info

kubectl -n fleet-default get openstackclusters.infrastructure.cluster.x-k8s.io
kubectl -n fleet-default get openstackservers.infrastructure.cluster.x-k8s.io
kubectl -n fleet-default get openstackmachinetemplates.infrastructure.cluster.x-k8s.io
kubectl -n fleet-default get openstackmachines.infrastructure.cluster.x-k8s.io

kubectl -n capo-system logs -l cluster.x-k8s.io/provider=infrastructure-openstack --tail=5
kubectl -n orc-system logs -l control-plane=controller-manager --tail=5

k0smotron info

kubectl -n fleet-default get remoteclusters.infrastructure.cluster.x-k8s.io
kubectl -n fleet-default get pooledremotemachines.infrastructure.cluster.x-k8s.io
kubectl -n fleet-default get remotemachinetemplates.infrastructure.cluster.x-k8s.io
kubectl -n fleet-default get remotemachines.infrastructure.cluster.x-k8s.io

kubectl -n capk0s-system logs -l cluster.x-k8s.io/provider=k0sproject-k0smotron --tail=5

# With `k0smotron.jumphost` enabled:
kubectl -n fleet-default get deploy/<cluster-name>-tunnel

Rollout Behavior

Changes to agentConfig, serverConfig, machine templates or the Kubernetes version all trigger a rolling replacement of the affected Machines.

Create first, replace second

By default, both the control plane and worker pools use maxSurge: 1: a new Machine is created (and joins the cluster) before the old one is deleted. ​```yaml controlPlane: rolloutStrategy: rollingUpdate: maxSurge: 1 # default type: RollingUpdate

workers:

  • name: worker-1 rollout: strategy: rollingUpdate: maxSurge: 1 # default type: RollingUpdate ​``` This keeps full capacity available throughout the rollout, but requires spare capacity to provision the extra Machine.

Remove first

Setting maxSurge: 0 reverses the order: the old Machine is deleted before the replacement is created.
This avoids needing any spare capacity, at the cost of reduced availability (one fewer Machine) for the duration of each replacement. ​```yaml controlPlane: rolloutStrategy: rollingUpdate: maxSurge: 0 type: RollingUpdate

workers:

  • name: worker-1 rollout: strategy: rollingUpdate: maxSurge: 0 type: RollingUpdate ​``` This is the recommended setting for cluster using k0smotron, because k0smotron pools target a fixed list of pre-existing addresses.

Uninstalling the Chart

helm delete <cluster-name> -n fleet-default

When the k0smotron.jumphost is enabled, additional manual cleanup is required:

kubectl -n fleet-default delete deployment,service,configmap -l cluster-template.io/component=jumphost-tunnel,cluster-template.io/clusterName=<cluster-name>

Restoring a Cluster from an ETCD Snapshot via Rancher

By default snapshots from the ETCD are made every 5h and stored locally on the corresponding cluster under /var/lib/rancher/rke2/server/db/snapshots.

To restore from a Snapshot or to manually create one, Rancher(>=2.15) provides the imported-day-2-ops feature (enabled by default).
It adds the Snapshot tab in the Rancher UI under Cluster Management -> Clusters -> <cluster>.

[!note] :notebook: Note
When enabling s3 in the ETCD backup config, the imported-day-2-ops will still create snapshots that are stored locally on the corresponding cluster.

Troubleshooting

Check DEBUGGING.md.

References

Deploy rke2-cluster-templates with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has rke2-cluster-templates on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.

  1. Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
  2. Place the chartrke2-cluster-templates is pinned at v9.1.0 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
  3. ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below
opentenant validate opentenant.yaml
terraform init && terraform apply