capi-cluster
by janip81
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
- A management cluster with the following controllers installed:
- Cluster API (CAPI)
- Cluster API Provider vSphere (CAPV)
- CAPI IPAM in-cluster provider
- Cluster API Add-ons Provider for Helm (if using
addons)
- vSphere with pre-built node templates (Ubuntu + kubeadm baked in — see image-builder)
- ArgoCD for GitOps-driven management (recommended)
Architecture
The chart renders the following Cluster API objects on the management cluster:
| Object | Purpose |
|---|---|
Cluster | Top-level CAPI cluster object |
VSphereCluster | vSphere infrastructure binding |
VSphereMachineTemplate (one per entry) | VM spec for CP or worker pools |
KubeadmControlPlane | Control plane lifecycle + kubeadm config |
MachineDeployment (one per entry) | Worker node pool (rolling or on-delete) |
KubeadmConfigTemplate | Worker bootstrap config |
MachineHealthCheck | Automatic node remediation |
InClusterIPPool | Static IP pool for node addresses |
Secret | vSphere credentials |
ClusterResourceSet + HelmChartProxy | In-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:LinkedCloneis faster but the disk cannot be expanded beyond the template size. UseFullClonefor 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
- Add a
machineTemplatesentry for the VM profile (or reuse an existing one). - Add a new entry to
machineDeploymentswith a uniquename. - Commit and push — ArgoCD applies the new
MachineDeploymentand 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:
- A new vSphere node template for the target version (built with image-builder).
- Updated
k8sVersionfields. - Updated
machineTemplatesentries (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:
| Addon | Key | Notes |
|---|---|---|
| vSphere CPI | addons.vsphereCPI | Cloud provider — required for node labels + CSI |
| metrics-server | addons.metricsServer | HPA/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
| Name | Url | |
|---|---|---|
| janip81 | [email protected] | https://github.com/janip81 |
Source Code
- https://github.com/janip81/helm-charts/tree/main/charts/capi-cluster
- https://github.com/kubernetes-sigs/cluster-api-provider-vsphere
- https://github.com/kubernetes-sigs/cluster-api
Values
| Key | Type | Default | Description |
|---|---|---|---|
| addons.metricsServer.chart.name | string | "metrics-server" | |
| addons.metricsServer.chart.repo | string | "https://kubernetes-sigs.github.io/metrics-server" | |
| addons.metricsServer.chart.version | string | "3.8.3" | |
| addons.metricsServer.enabled | bool | false | |
| addons.metricsServer.name | string | "metrics-server" | |
| addons.metricsServer.release.namespace | string | "kube-system" | |
| addons.metricsServer.release.values.image.pullPolicy | string | "IfNotPresent" | |
| addons.metricsServer.release.values.image.repository | string | "registry.k8s.io/metrics-server/metrics-server" | |
| addons.metricsServer.release.values.image.tag | string | "" | |
| addons.vsphereCPI.chart.name | string | nil | |
| addons.vsphereCPI.chart.repo | string | nil | |
| addons.vsphereCPI.chart.version | string | nil | |
| addons.vsphereCPI.enabled | bool | false | |
| addons.vsphereCPI.name | string | "vsphere-cpi" | |
| addons.vsphereCPI.release.namespace | string | nil | |
| addons.vsphereCPI.release.values | object | {} | |
| cluster.bgpPolicyVlan | string | "vlan201" | |
| cluster.cidrBlocks | string | "10.245.0.0/16" | |
| cluster.controlPlaneEndpoint | string | "host.domain.com" | |
| cluster.controlPlaneEndpointIP | string | "192.168.1.11" | |
| cluster.name | string | "clustername" | |
| cluster.skipKubeProxy | bool | true | |
| controlPlaneNodes.k8sVersion | string | "1.35.0" | |
| controlPlaneNodes.replicas | int | 3 | |
| controlPlaneNodes.vspehereMachineTemplate | string | "ubnt2204-2cpu-4g-135" | |
| etcdDefrag.enabled | bool | false | |
| etcdDefrag.failedJobsHistoryLimit | int | 3 | |
| etcdDefrag.image | string | "" | |
| etcdDefrag.schedule | string |
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.
- Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
- Place the chartcapi-cluster is pinned at v0.0.102 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
- 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