capi-cluster

by janip81

Helm chartv0.0.102App 1.35Apache-2.0Verified publisher

An unofficial Helm chart to deploy workload cluster with Cluster API

About this chart

capi-cluster

An unofficial Helm chart to deploy workload cluster with Cluster API

This chart provisions a full Kubernetes workload cluster on vSphere using Cluster API and CAPV. It is designed to be managed by ArgoCD running on a management cluster where CAPI controllers are installed.

Homepage: https://github.com/janip81/helm-charts/tree/main/charts/capi-cluster

Prerequisites

Architecture

The chart renders the following Cluster API objects on the management cluster:

ObjectPurpose
ClusterTop-level CAPI cluster object
VSphereClustervSphere infrastructure binding
VSphereMachineTemplate (one per entry)VM spec for CP or worker pools
KubeadmControlPlaneControl plane lifecycle + kubeadm config
MachineDeployment (one per entry)Worker node pool (rolling or on-delete)
KubeadmConfigTemplateWorker bootstrap config
MachineHealthCheckAutomatic node remediation
InClusterIPPoolStatic IP pool for node addresses
SecretvSphere credentials
ClusterResourceSet + HelmChartProxyIn-cluster addons (CPI, metrics-server, etcd-defrag)

CAPI reconciles these objects and provisions VMs on vSphere. kube-vip runs as a static pod on control-plane nodes to provide the VIP.

Install / GitOps Usage

This chart is intended to be deployed via ArgoCD using the avp-helm plugin (or plain Helm with a values file). Each cluster has its own cluster-values.yaml:

# prod/clusters/prod-k8s/cluster-values.yaml
cluster: prod-k8s
targetRevision: "0.0.94"
values: |
  cluster:
    name: prod-k8s
    controlPlaneEndpoint: "k8s.example.com"
    controlPlaneEndpointIP: "192.168.101.11"
    cidrBlocks: "10.244.0.0/16"
  ...

The ArgoCD ApplicationSet picks up the cluster-values.yaml files and creates one Application per cluster.

Machine Templates

machineTemplates defines the VM hardware profiles available to both the control plane and worker pools. Each template maps to a VSphereMachineTemplate object.

machineTemplates:
  - name: ubnt2204-4cpu-8g-135        # referenced by machineDeployments[].vspehereMachineTemplate
    cpu: 4
    memory: 8192
    diskSize: 35
    cloneMode: FullClone               # FullClone or LinkedClone
    isoTemplate: ubuntu-2404-kube-v1.35.0
    vcenterDatastore: SSD01
    vcenterFolder: kubernetes/prod-k8s
    network: VLAN101
    storagePolicyName: ""

The naming convention <os>-<cpu>cpu-<mem>g-<k8sMinor> makes it obvious which k8s version the template was built for and prevents accidental reuse across upgrades.

Note on cloneMode: LinkedClone is faster but the disk cannot be expanded beyond the template size. Use FullClone for production.

PCI Passthrough Templates

For nodes with PCI passthrough devices (e.g. GPU, network adapters) add pciDevices and optionally customVMXKeys:

machineTemplates:
  - name: ubnt2204-4cpu-8g-pci-135
    cpu: 4
    memory: 8192
    diskSize: 35
    cloneMode: FullClone
    isoTemplate: ubuntu-2404-kube-v1.35.0
    vcenterDatastore: SSD01
    network: VLAN101
    pciDevices:
      - deviceId: 21      # decimal (not hex)
        vendorId: 6418
    customVMXKeys:
      pciPassthru0.msiEnabled: "TRUE"

Control Plane

controlPlaneNodes:
  k8sVersion: 1.35.0
  vspehereMachineTemplate: ubnt2204-2cpu-4g-135   # must match a machineTemplates[].name
  replicas: 3

Three replicas is the minimum for a production HA control plane. kube-vip provides the VIP; its static-pod manifest is injected via KubeadmControlPlane.files.

Worker Groups (MachineDeployments)

Each entry under machineDeployments creates a MachineDeployment and a KubeadmConfigTemplate. You can have as many groups as needed — e.g. one general pool and one dedicated pool for nodes with special hardware.

machineDeployments:
  - name: md-0
    vspehereMachineTemplate: ubnt2204-4cpu-8g-135
    k8sVersion: 1.35.0
    replicas: 3
    nodeLabels:
      node-role.kubernetes.io/worker: "true"

  - name: md-pci
    vspehereMachineTemplate: ubnt2204-4cpu-8g-pci-135
    k8sVersion: 1.35.0
    replicas: 1
    nodeLabels:
      node-role.kubernetes.io/worker: "true"
    taints:
      - key: dedicated
        value: pci
        effect: NoSchedule
    strategy:
      type: OnDelete      # required for PCI nodes — see upgrade section

Adding a New Worker Group

  1. Add a machineTemplates entry for the VM profile (or reuse an existing one).
  2. Add a new entry to machineDeployments with a unique name.
  3. Commit and push — ArgoCD applies the new MachineDeployment and CAPI provisions the VMs.

Removing a Worker Group

Scale the group to replicas: 0 first (drains and deletes nodes), then remove the entry on a follow-up commit. This avoids orphaned nodes.

Cluster Autoscaler Integration

Set replicas: 0 and add autoscaler annotations so the CA controls the replica count:

machineDeployments:
  - name: md-autoscale
    replicas: 0
    machineDeploymentAnnotations:
      cluster.x-k8s.io/cluster-api-autoscaler-node-group-min-size: "0"
      cluster.x-k8s.io/cluster-api-autoscaler-node-group-max-size: "10"
    machineSetLabels:
      autoscaler: enabled

ArgoCD must be configured to ignore /spec/replicas drift on MachineDeployment objects (the autoscaler owns that field):

# ArgoCD Application ignoreDifferences
ignoreDifferences:
  - group: cluster.x-k8s.io
    kind: MachineDeployment
    jsonPointers:
      - /spec/replicas

Upgrading the Cluster

A Kubernetes minor version upgrade touches three things:

  1. A new vSphere node template for the target version (built with image-builder).
  2. Updated k8sVersion fields.
  3. Updated machineTemplates entries (or new entries) pointing to the new vSphere template.

Step-by-step upgrade (e.g. 1.34 → 1.35)

1. Add new machine templates (keep the old ones — CAPI still references them during rollout):

machineTemplates:
  # existing — do NOT remove yet
  - name: ubnt2204-2cpu-4g-134
    isoTemplate: ubuntu-2404-kube-v1.34.0
    ...
  - name: ubnt2204-4cpu-8g-134
    isoTemplate: ubuntu-2404-kube-v1.34.0
    ...
  # new
  - name: ubnt2204-2cpu-4g-135
    isoTemplate: ubuntu-2404-kube-v1.35.0
    ...
  - name: ubnt2204-4cpu-8g-135
    isoTemplate: ubuntu-2404-kube-v1.35.0
    ...

2. Update the control plane (CAPI rolls CP nodes one at a time, majority always healthy):

controlPlaneNodes:
  k8sVersion: 1.35.0
  vspehereMachineTemplate: ubnt2204-2cpu-4g-135

3. Update each worker MachineDeployment (CAPI default is RollingUpdate — maxSurge: 1, maxUnavailable: 0):

machineDeployments:
  - name: md-0
    k8sVersion: 1.35.0
    vspehereMachineTemplate: ubnt2204-4cpu-8g-135

4. Commit and push. ArgoCD syncs → CAPI rolls control plane first, then each MachineDeployment.

5. After all nodes are on the new version, remove the old machineTemplates entries and commit again.

Upgrading Nodes with PCI Passthrough (OnDelete strategy)

CAPI's default rolling upgrade provisions a new VM before deleting the old one. For nodes with PCI devices this fails — the device is physically bound to the old VM and cannot be reassigned while it is running.

The solution is strategy.type: OnDelete: CAPI will not replace a node automatically; you trigger replacement by manually deleting the Machine object.

Upgrade procedure for a PCI node group:

# values.yaml — point to new template first, strategy stays OnDelete
machineDeployments:
  - name: md-pci
    k8sVersion: 1.35.0
    vspehereMachineTemplate: ubnt2204-4cpu-8g-pci-135
    strategy:
      type: OnDelete

After ArgoCD syncs (template reference updated, no nodes replaced yet):

# 1. Drain the node gracefully
kubectl drain <node-name> --ignore-daemonsets --delete-emptydir-data

# 2. Delete the Machine — this powers off and removes the old VM, freeing the PCI device
kubectl -n <cluster-namespace> delete machine <machine-name>

# CAPI now provisions a fresh VM with the new template and the PCI device attached
# 3. Watch until the new node joins and becomes Ready
kubectl get machines -n <cluster-namespace> -w

If you have multiple PCI nodes in the group, repeat steps 1–3 for each node sequentially — the PCI device must be free before the next VM can claim it.

etcd Defrag CronJob

Runs weekly compact + defrag on the workload cluster's etcd. The job discovers etcd members dynamically (no static IPs needed) and runs on a control-plane node via nodeSelector + toleration.

etcdDefrag:
  enabled: true
  schedule: "0 3 * * 0"    # Sunday 03:00 UTC
  successfulJobsHistoryLimit: 3
  failedJobsHistoryLimit: 3

The job is delivered via ClusterResourceSet — it is applied to the workload cluster by CAPI, not ArgoCD.

Addons

In-cluster addons are installed into the workload cluster via HelmChartProxy (CAPI Addon Provider for Helm). Currently supported:

AddonKeyNotes
vSphere CPIaddons.vsphereCPICloud provider — required for node labels + CSI
metrics-serveraddons.metricsServerHPA/VPA metrics source
addons:
  vsphereCPI:
    enabled: true
    name: vsphere-cpi
    chart:
      repo: https://kubernetes.github.io/cloud-provider-vsphere
      name: vsphere-cpi
      version: 1.35.0
    release:
      namespace: kube-system
      values:
        config:
          vcenter: vcenter.example.com

Health Checks

MachineHealthCheck objects are created for both the control plane and each worker group. Unhealthy nodes (Ready=False or Unknown for the configured timeout) are automatically replaced by CAPI.

healthChecks:
  controlplane:
    maxUnhealthy: 100%          # never remediate if all CP nodes are down
    nodeStartupTimeoutSeconds: 900
    unhealthyTimeoutUnknown: 300
    unhealthyTimeoutFalse: 300
  workernodes:
    maxUnhealthy: 40%           # allow up to 40% down before halting remediation
    nodeStartupTimeoutSeconds: 900
    unhealthyTimeoutUnknown: 300
    unhealthyTimeoutFalse: 300

Pod Security Standards

Cluster-wide PSS admission can be enabled. kube-system is always exempted.

podSecurityStandard:
  enabled: true
  enforce: baseline
  audit: restricted
  warn: restricted
  exemptions:
    namespaces:
      - kube-system

Gateway API CRDs

When gatewayapi.enabled: true the chart installs Gateway API CRDs via a ClusterResourceSet using the official upstream bundle.

gatewayapi:
  enabled: true
  version: v1.3.0
  channel: standard       # or experimental
  applyStrategy: ApplyOnce

Maintainers

NameEmailUrl
janip81[email protected]https://github.com/janip81

Source Code

Values

KeyTypeDefaultDescription
addons.metricsServer.chart.namestring"metrics-server"
addons.metricsServer.chart.repostring"https://kubernetes-sigs.github.io/metrics-server"
addons.metricsServer.chart.versionstring"3.8.3"
addons.metricsServer.enabledboolfalse
addons.metricsServer.namestring"metrics-server"
addons.metricsServer.release.namespacestring"kube-system"
addons.metricsServer.release.values.image.pullPolicystring"IfNotPresent"
addons.metricsServer.release.values.image.repositorystring"registry.k8s.io/metrics-server/metrics-server"
addons.metricsServer.release.values.image.tagstring""
addons.vsphereCPI.chart.namestringnil
addons.vsphereCPI.chart.repostringnil
addons.vsphereCPI.chart.versionstringnil
addons.vsphereCPI.enabledboolfalse
addons.vsphereCPI.namestring"vsphere-cpi"
addons.vsphereCPI.release.namespacestringnil
addons.vsphereCPI.release.valuesobject{}
cluster.bgpPolicyVlanstring"vlan201"
cluster.cidrBlocksstring"10.245.0.0/16"
cluster.controlPlaneEndpointstring"host.domain.com"
cluster.controlPlaneEndpointIPstring"192.168.1.11"
cluster.namestring"clustername"
cluster.skipKubeProxybooltrue
controlPlaneNodes.k8sVersionstring"1.35.0"
controlPlaneNodes.replicasint3
controlPlaneNodes.vspehereMachineTemplatestring"ubnt2204-2cpu-4g-135"
etcdDefrag.enabledboolfalse
etcdDefrag.failedJobsHistoryLimitint3
etcdDefrag.imagestring""
etcdDefrag.schedulestring

Deploy capi-cluster with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has capi-cluster 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 chartcapi-cluster is pinned at v0.0.102 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