Talos Kubernetes Clusters on Proxmox with Cluster API
In this post, I’ll use Cluster API to create Talos Linux Kubernetes clusters on Proxmox VE, so that a cluster is built from a few Kubernetes resources instead of by hand. Cluster API runs in a small Talos management cluster and talks to the Proxmox API. It clones the VMs, hands out the IPs, generates the Talos configs and bootstraps the cluster. Scaling, upgrading and deleting a cluster is then a matter of changing those resources.
In A Simple Talos Kubernetes Cluster on Proxmox, I built the cluster by hand. I created the VMs, generated the configs, applied them to the nodes and bootstrapped etcd. It’s only a handful of commands, but you still have to run each one yourself, and every new cluster leaves you with another set of config files to keep track of.
Cluster API, which I’ll refer to as CAPI for the rest of the post, turns this around. A cluster is described with Kubernetes resources, just like a Deployment describes pods. You apply them to a management cluster, and controllers running there create the VMs and the cluster to match. If you want three workers instead of two, you change a number. If a cluster is no longer needed, you delete a resource and the VMs are gone.
CAPI itself doesn’t know anything about Proxmox or Talos. The core only deals with clusters and machines in general, and leaves the rest to providers, each with one job. This post uses the core and four providers. Their project names are a mouthful, so I’ll call them by their role for the rest of the post.
- The core: cluster-api. It brings the
Cluster,MachineandMachineDeploymentresources, and the logic that ties them together. - The bootstrap provider: cluster-api-bootstrap-provider-talos. It generates the Talos machine config for each node, both control plane and workers.
- The control plane provider: cluster-api-control-plane-provider-talos. It creates the control plane nodes and bootstraps etcd.
- The Proxmox provider: cluster-api-provider-proxmox. It clones the VMs in Proxmox and gives them their IPs. In CAPI terms, this is the infrastructure provider.
- The IPAM provider: cluster-api-ipam-provider-in-cluster. It keeps the pool of node IPs and hands them out to the Proxmox provider.
Both clusters run Talos v1.14.5. The workload cluster runs Kubernetes 1.36.5, and the management cluster gets the
default Kubernetes version of that Talos release. The provider versions matter more than usual, since they must
all support the same CAPI version. At the time of writing, the Proxmox provider v0.9 only supports CAPI v1.12, so the
core is pinned to that. The exact versions are in the clusterctl init command further down.
How It Fits Together¶
This post uses two clusters. The management cluster is a single Talos node that runs CAPI and the providers, and nothing else. It is the only cluster built by hand, the same way as in the first post. The workload cluster is created by CAPI, with one control plane node and two workers, and so is every cluster after it.
flowchart LR
you[kubectl apply] --> mgmt
subgraph mgmt[Management cluster]
capi[CAPI + providers]
end
capi -- Proxmox API --> pve[Proxmox VE]
pve -- clones template --> vms
subgraph vms[Workload cluster]
cp[Control plane]
w1[Worker]
w2[Worker]
end
capi -- Talos and Kubernetes API --> vms
When a new node is needed, this is what happens.
- A
Machineis created. For control plane nodes the control plane provider does this, for workers it is theMachineDeployment. - The bootstrap provider generates the Talos machine config for that
Machine. - The IPAM provider hands out an IP from the pool.
- The Proxmox provider clones the template into a new VM and attaches a small ISO with the machine config and the
network settings. Talos reads it with its
nocloudplatform, the same way a cloud VM reads its user data. - The VM boots Talos from the template’s ISO, reads the config, installs itself to the disk and reboots.
- On the first control plane node, the control plane provider bootstraps etcd. The core then waits for the node to
show up in Kubernetes, and the
Machineis ready.
Since the nodes created by CAPI get static IPs from the pool, they don't need DHCP static leases like in the previous posts. Their network only has to exist. The management cluster is built by hand, so it still needs a fixed IP of its own, as described below.
Prerequisites¶
You need three tools on your workstation.
talosctlcreates the management cluster. Install it from the Talos docs.kubectlapplies the cluster resources. Install it from the Kubernetes docs.clusterctlinstalls CAPI and the providers. Install it from the CAPI quick start.
You also need a root shell on the Proxmox host, to create the API user and the role for CAPI.
IP Plan¶
The nodes live on 10.0.30.0/24, with the router at 10.0.30.1. Replace the IPs with something from your own
network.
| What | Value | Notes |
|---|---|---|
| Proxmox API | https://10.0.10.10:8006 |
|
| Management cluster | 10.0.30.10 | |
| Workload cluster VIP | 10.0.30.20 | The Kubernetes API endpoint |
| Workload cluster node IPs | 10.0.30.21 - 10.0.30.29 | Handed out by CAPI |
The VIP must be outside the node IP range, otherwise CAPI could give it to a node.
Building the Talos Image¶
The image is the same as in the previous posts, built by the Image Factory with the
siderolabs/qemu-guest-agent extension and the Nocloud platform. The guest agent matters more than usual here,
since the Proxmox provider uses it to check that the VM is running.
SCHEMATIC=ce4c980550dd2ab1b17bbf2b08801c7eb59418eafe8f279833297925d67c7515
TALOS=v1.14.5
curl -Lo talos-$TALOS-nocloud-amd64.iso \
https://factory.talos.dev/image/$SCHEMATIC/$TALOS/nocloud-amd64.iso
Upload the ISO to the ISO storage in Proxmox. The same ISO is used both for the management cluster and for the template later.
The Management Cluster¶
The management cluster is created exactly like the control plane in my previous post, so I’ll keep this part short. Create a VM with 2 vCPU, 4 GB of memory and a 10 GB disk, with the guest agent enabled and ballooning disabled. Boot it from the ISO, and wait for maintenance mode.
The only difference is that this cluster has a single node. By default, Talos taints control plane nodes so normal
workloads don’t run there, which would leave the CAPI controllers with nowhere to go. Create a patch called
controlplane-patch.yaml that removes the taint.
apiVersion: v1alpha1
kind: KubeNodeConfig
taints:
node-role.kubernetes.io/control-plane:
$patch: delete
By default, Talos gets its IP from DHCP on every boot. The simplest way to keep it at 10.0.30.10 is a static lease.
Reserve the IP for the MAC address of the VM on your DHCP server.
If you’d rather not depend on the DHCP server, you can set a static IP in the Talos config instead.
Setting a static IP in the Talos config
In maintenance mode, the node still has an IP from DHCP. You can see it on the Summary page of the VM in
Proxmox, since the guest agent is in the ISO, or on the Talos dashboard in the VM console. Once the config is
applied, the node uses 10.0.30.10 instead.
Find the name of the network interface while the node is in maintenance mode, using the IP it got from DHCP.
Then add a LinkConfig and a ResolverConfig to controlplane-patch.yaml, with your interface name instead
of eth0.
---
apiVersion: v1alpha1
kind: LinkConfig
name: eth0
up: true
addresses:
- address: 10.0.30.10/24
routes:
- gateway: 10.0.30.1
---
apiVersion: v1alpha1
kind: ResolverConfig
nameservers:
- address: 10.0.30.1
When you apply the config further down, use the IP the node got from DHCP instead of 10.0.30.10. After the
reboot, the node answers on 10.0.30.10.
Generate the secrets. Keep secrets.yaml somewhere safe.
Generate the config with the installer image and the patch. talosctl names the client config talosconfig, so
rename it to management.talosconfig to tell it apart from the one for the workload cluster later.
SCHEMATIC=ce4c980550dd2ab1b17bbf2b08801c7eb59418eafe8f279833297925d67c7515
TALOS=v1.14.5
talosctl gen config capi-mgmt https://10.0.30.10:6443 \
--with-secrets secrets.yaml \
--install-image factory.talos.dev/nocloud-installer/$SCHEMATIC:$TALOS \
--config-patch-control-plane @controlplane-patch.yaml
mv talosconfig management.talosconfig
Apply the config. Talos installs itself to the disk and reboots.
When the node is back up after the reboot, it waits for etcd to be bootstrapped.
Point talosctl at the node and bootstrap etcd.
export TALOSCONFIG=./management.talosconfig
talosctl config endpoint 10.0.30.10
talosctl config node 10.0.30.10
talosctl bootstrap
Wait for the cluster to become healthy.
Fetch the kubeconfig and check the node.
talosctl kubeconfig ./management.kubeconfig
export KUBECONFIG=./management.kubeconfig
kubectl get nodes
The management cluster doesn’t need a VIP. Nothing outside it talks to its Kubernetes API except you, and if it goes down, the workload clusters keep running. CAPI just can’t change them until it is back.
A Proxmox User for CAPI¶
The Proxmox provider uses an API token to talk to the Proxmox API, and every token belongs to a user. Start by creating a dedicated user for CAPI. Run the commands in this section on the Proxmox host.
Next, the role. Proxmox has predefined roles like PVEVMAdmin and PVEDatastoreAdmin, but covering everything CAPI
needs with them gives the user a lot more than it uses, like console, snapshot, backup and migrate access on every
VM, and full admin over storage. A custom role with only the privileges the Proxmox provider actually uses is tighter.
pveum role add CAPI --privs "\
VM.Audit VM.Clone VM.Allocate VM.PowerMgmt \
VM.Config.CPU VM.Config.Memory VM.Config.Disk \
VM.Config.Network VM.Config.Options VM.Config.CDROM \
VM.GuestAgent.Audit \
Datastore.Audit Datastore.AllocateSpace Datastore.AllocateTemplate Datastore.Allocate \
Sys.Audit SDN.Use"
What each privilege is for
| Privilege | Needed for |
|---|---|
VM.* |
Cloning the template, creating and deleting the VM, setting CPU, memory, disk, network and tags, attaching the ISO, powering on and pinging the guest agent |
Datastore.Audit |
Listing storages, to find the template disk and the ISO storage |
Datastore.AllocateSpace |
Allocating the disk of the clone |
Datastore.AllocateTemplate |
Uploading the ISO with the machine config |
Datastore.Allocate |
Deleting that ISO again when the VM is deleted |
Sys.Audit |
Reading the node status, to decide where to place the VM |
SDN.Use |
Attaching the network device to the bridge and VLAN, checked since Proxmox 8 |
Grant the role to the user on /, so it applies to every VM, storage and bridge.
Finally, the token.
The token secret is only shown once, so copy it now.
--privsep 0 turns off privilege separation, which means the token gets exactly the permissions of the user. With
the default --privsep 1, the token only gets what is granted to both the user and the token itself, and since a
new token has no grants of its own, it can do nothing at all. That is useful when one user has several tokens with
different rights, but capi@pve only exists for CAPI, so there is nothing to gain.
Check what the token ends up with.
pveum user token list capi@pve # privsep should be 0
pveum user permissions 'capi@pve!capmox' --path /
Creating the Template¶
The Proxmox provider doesn’t create VMs from scratch, it clones a template. Create a VM with the following settings, but don’t start it.
- Talos ISO in the CD-ROM drive, the one downloaded in Building the Talos Image.
- QEMU Guest Agent enabled.
- Ballooning Device unticked under Memory, with Advanced ticked to see it.
- CPU type left at
x86-64-v2-AES. - A 10 GB disk on VirtIO SCSI.
The template doesn’t have to match the size of the nodes, since CPU, memory and disk are set on each clone by CAPI.
The disk is still the one to watch. The Proxmox provider resizes the disk of the clone to the size you ask for, and
Proxmox can only grow disks, never shrink them. If the template has the default 32 GB disk and you ask for 10 GB,
the clone gets stuck with resize: shrinking disks is not supported. Make the template disk smaller than any node
you’ll create, and let CAPI grow it.
Right-click the VM and choose Convert to template, and note the VM ID. In this post it is 1001.
Versioning the template
A template can’t be changed once it is converted, and the Talos version is baked into its ISO. A practical way to
handle new Talos versions is to keep a normal VM with all the settings, like capi-talos-template-raw, and never
start it. For a new version, swap the ISO on it, clone it to capi-talos-1.14.5-template and convert the clone.
Installing Cluster API¶
The Proxmox provider reads its credentials from environment variables when it is installed. Export them in the same
shell you run clusterctl from.
export PROXMOX_URL='https://10.0.10.10:8006'
export PROXMOX_TOKEN='capi@pve!capmox'
export PROXMOX_SECRET='<the token secret>'
Missing credentials fail silently
If clusterctl can't see the variables, it doesn't complain. It installs the Proxmox provider with empty
credentials, and every cluster later fails with No credentials found, ProxmoxCluster missing credentialsRef.
Install the providers. clusterctl knows all of them by name, and without a version it installs the latest of
each. That doesn’t work here. Every provider is built against a range of CAPI versions, and at the time of writing,
the Proxmox provider v0.9 only supports CAPI v1.12. The core is pinned to v1.12 for that reason.
Even when the latest versions happen to line up, pinning means I know what I’m running.
clusterctl init \
--core cluster-api:v1.12.11 \
--bootstrap talos:v0.6.13 \
--control-plane talos:v0.5.14 \
--infrastructure proxmox:v0.9.2 \
--ipam in-cluster:v1.1.1
clusterctl also installs cert-manager, which the providers use for their webhook certificates.
Check that every provider is installed, and that the credentials made it into the Proxmox provider.
kubectl get providers -A
kubectl -n capmox-system get secret capmox-manager-credentials -o jsonpath='{.data.url}' | base64 -d; echo
NAMESPACE NAME TYPE PROVIDER VERSION
cabpt-system bootstrap-talos BootstrapProvider talos v0.6.13
cacppt-system control-plane-talos ControlPlaneProvider talos v0.5.14
capi-ipam-in-cluster-system ipam-in-cluster IPAMProvider in-cluster v1.1.1
capi-system cluster-api CoreProvider cluster-api v1.12.11
capmox-system infrastructure-proxmox InfrastructureProvider proxmox v0.9.2
https://10.0.10.10:8006
The namespaces are named after the abbreviations the projects go by. capmox is the Proxmox provider, and cabpt
and cacppt are the Talos bootstrap and control plane providers.
To check for newer versions later, clusterctl upgrade plan lists the installed version of each provider next to the
newest one it can upgrade to.
The Workload Cluster¶
A CAPI cluster is a handful of resources that point to each other. The generic CAPI resources, like Cluster, leave
the platform details to a provider-specific resource, like ProxmoxCluster. That is why the same Cluster resource
works on AWS, vSphere or Proxmox.
| Resource | Provider | Purpose |
|---|---|---|
Cluster |
Core | The top level resource, which points at the two below |
ProxmoxCluster |
Proxmox | The Kubernetes API endpoint and the node IP pool |
TalosControlPlane |
Control plane | The control plane nodes and their Talos config |
ProxmoxMachineTemplate |
Proxmox | The VM spec, one for the control plane and one for the workers |
MachineDeployment |
Core | The worker nodes, like a Deployment for machines |
TalosConfigTemplate |
Bootstrap | The Talos config for the workers |
The arrows point from a resource to the resources it references.
flowchart TD
cluster[Cluster] -- infrastructureRef --> pxc[ProxmoxCluster]
cluster -- controlPlaneRef --> tcp[TalosControlPlane]
tcp -- infrastructureTemplate --> cpt[ProxmoxMachineTemplate<br>homelab-1-cp]
md[MachineDeployment] -- clusterName --> cluster
md -- bootstrap.configRef --> tct[TalosConfigTemplate]
md -- infrastructureRef --> wt[ProxmoxMachineTemplate<br>homelab-1-workers]
The cluster in this post is called homelab-1. All its resources go in a homelab-1 namespace in the management
cluster, and in a homelab-1 folder on disk. That keeps each cluster together, both when listing resources and when
applying them.
Create the folder for the files in the rest of this section.
The Proxmox Cluster¶
The ProxmoxCluster holds the parts of the cluster that are shared by every node, rather than set per VM. It
defines which Proxmox nodes the VMs may be placed on, the Kubernetes API endpoint, and the pool of node IPs with the
gateway and DNS servers. When a node is created, the Proxmox provider takes an IP from this pool and writes it, with
the prefix, gateway and DNS servers, into the network config of the VM.
homelab-1/proxmox-cluster.yaml
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha2
kind: ProxmoxCluster
metadata:
name: homelab-1
namespace: homelab-1
spec:
# The Proxmox nodes the VMs may be placed on, as named in the Proxmox UI.
allowedNodes:
- proxmox
# The Kubernetes API endpoint, which is the VIP. CAPI doesn't create it,
# it is set up by Talos in the control plane config below.
controlPlaneEndpoint:
host: 10.0.30.20
port: 6443
# The pool the IPAM provider hands out node IPs from.
# addresses is a range, or a list of ranges, within the subnet. The prefix and
# gateway are written into the network config of every node.
ipv4Config:
addresses:
- 10.0.30.21-10.0.30.29
prefix: 24
gateway: 10.0.30.1
dnsServers:
- 10.0.30.1
# The Proxmox provider places VMs on the Proxmox node with the most free
# memory, and won't go beyond this percentage of the host's memory. My
# host runs ZFS, and the ZFS cache (ARC) needs memory too, so 15% is left
# for it and Proxmox itself.
schedulerHints:
memoryAdjustment: 85
The Machine Template¶
The ProxmoxMachineTemplate describes the VM behind each node. It says which Proxmox template to clone, and sets the
CPU, memory, disk and network of the clone. It is a template in the CAPI sense, so nothing is created from it
directly. Every time a node is needed, CAPI makes a ProxmoxMachine from it, and the Proxmox provider turns that
into one VM. This one is for the control plane, and the workers get one of their own further down.
homelab-1/cp-machine-template.yaml
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha2
kind: ProxmoxMachineTemplate
metadata:
name: homelab-1-cp
namespace: homelab-1
spec:
template:
spec:
# The VM ID of the template, and the Proxmox node it lives on.
sourceNode: proxmox
templateID: 1001
# A full clone doesn't depend on the template, unlike a linked clone.
full: true
# The storage the disk of the clone goes on. ZFS only stores raw disks.
storage: local-zfs
format: raw
numSockets: 1
numCores: 2
memoryMiB: 2048
disks:
bootVolume:
disk: scsi0
# The disk of the clone is grown to this size, so it can't be
# smaller than the template disk.
sizeGb: 10
network:
networkDevices:
- name: net0
bridge: vmbr0
model: virtio
# The node network is VLAN 30 in my setup. Leave it out if the
# nodes are on the untagged network of the bridge.
vlan: 30
defaultIPv4: true
# Tags are added to the VM in Proxmox. They also work around a quirk in
# the Proxmox provider v0.9, where a clone that already matches the spec
# gets stuck in Cloning, since there is no config change to move it along.
tags:
- controlplane
- talos
# The Proxmox provider normally runs "cloud-init status" through the guest
# agent to see when the VM is ready. Talos doesn't have cloud-init, so it
# would never pass.
checks:
skipCloudInitStatus: true
# Writes the provider ID of the VM into the nocloud metadata. More on that below.
metadataSettings:
providerIDInjection: true
The name of the machine template becomes part of the VM name and the hostname of the node, like
homelab-1-cp-4vw6t, so naming it after the cluster and role makes it easy to see in Proxmox what a VM belongs to.
The Control Plane¶
The TalosControlPlane manages the control plane nodes, the same way a MachineDeployment manages the workers. It
keeps the number of control plane nodes at replicas, uses the machine template above for their VMs, and holds the
Talos config they get. It also bootstraps etcd on the first node, and when the Kubernetes version changes, it rolls
out new control plane nodes one at a time.
homelab-1/control-plane.yaml
apiVersion: controlplane.cluster.x-k8s.io/v1alpha3
kind: TalosControlPlane
metadata:
name: homelab-1
namespace: homelab-1
spec:
version: v1.36.5
replicas: 1
infrastructureTemplate:
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha2
kind: ProxmoxMachineTemplate
name: homelab-1-cp
namespace: homelab-1
controlPlaneConfig:
controlplane:
generateType: controlplane
talosVersion: v1.14.5
strategicPatches:
- |
cluster:
externalCloudProvider:
enabled: true
manifests:
- https://raw.githubusercontent.com/siderolabs/talos-cloud-controller-manager/v1.14.0/docs/deploy/cloud-controller-manager.yml
---
apiVersion: v1alpha1
kind: KubeTalosAPIAccessConfig
allowedRoles:
- os:reader
allowedKubernetesNamespaces:
- kube-system
---
apiVersion: v1alpha1
kind: UnattendedInstallConfig
installer:
image: factory.talos.dev/nocloud-installer/ce4c980550dd2ab1b17bbf2b08801c7eb59418eafe8f279833297925d67c7515:v1.14.5
provisioning:
diskSelector:
match: disk.dev_path == "/dev/sda"
---
apiVersion: v1alpha1
kind: Layer2VIPConfig
name: 10.0.30.20
link: eth0
version is the Kubernetes version, and talosVersion tells the bootstrap provider which Talos version to generate
the config for. The rest is plain Talos config, applied as patches on top of what the bootstrap provider generates.
externalCloudProviderinstalls the Talos cloud controller manager (CCM) from the manifest, and makes the kubelet leave node initialization to it.KubeTalosAPIAccessConfiglets pods inkube-system, like the CCM, read from the Talos API with theos:readerrole. More on why the CCM is needed below.UnattendedInstallConfigtells Talos what to install and where. The VM boots from the Talos ISO in the template's CD-ROM drive, but what ends up on the disk is the installer image. The guest agent must be in both, since the Proxmox provider talks to it before and after the install. Any other extensions only need to be in the installer image. The disk selector points the install at the SCSI disk.Layer2VIPConfigputs the VIP from theProxmoxClusteron the control plane, exactly like in Moving the Talos Kubernetes API to a Virtual IP.
CAPI has to know which Kubernetes node belongs to which Machine, and it matches them by the provider ID, a field on
the node like proxmox://0d742176-.... Until the node has one, the Machine never becomes ready and CAPI keeps
waiting. On a cloud, the cloud’s own controller manager sets it. On Proxmox, the pieces fit together like this.
providerIDInjectionon the machine template makes the Proxmox provider writeproxmox://<vm-uuid>into the nocloud metadata.- Talos reads it as part of its platform metadata.
- The Talos CCM reads the platform metadata of each
node through the Talos API, and sets
spec.providerIDon the KubernetesNoderesource. - CAPI finds the
Nodewith the same provider ID as theProxmoxMachine, links it to theMachine, and theMachinebecomes ready.
The Layer2VIPConfig, the CCM manifests and the KubeTalosAPIAccessConfig are only for the control plane. The
workers get their own config below.
The Cluster¶
The Cluster is the top-level resource, and the one CAPI starts from. It doesn’t hold much configuration itself,
it only points at the TalosControlPlane and the ProxmoxCluster and ties them together. Every other resource of
the cluster refers back to it by name, which is how CAPI knows what belongs to it. It is also the resource you
delete to tear the cluster down.
homelab-1/cluster.yaml
apiVersion: cluster.x-k8s.io/v1beta2
kind: Cluster
metadata:
name: homelab-1
namespace: homelab-1
spec:
controlPlaneRef:
apiGroup: controlplane.cluster.x-k8s.io
kind: TalosControlPlane
name: homelab-1
infrastructureRef:
apiGroup: infrastructure.cluster.x-k8s.io
kind: ProxmoxCluster
name: homelab-1
The Workers¶
The control plane gets its Talos config and its number of nodes from the TalosControlPlane. For the workers, those
are two separate resources, and with a machine template of their own, the workers are three resources in all.
The Worker Machine Template¶
The workers get a ProxmoxMachineTemplate of their own, with a bit more memory. Apart from the name, memory and
tags, it is the same as the control plane template, so the comments are left out here.
homelab-1/workers-machine-template.yaml
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha2
kind: ProxmoxMachineTemplate
metadata:
name: homelab-1-workers
namespace: homelab-1
spec:
template:
spec:
sourceNode: proxmox
templateID: 1001
full: true
storage: local-zfs
format: raw
numSockets: 1
numCores: 2
memoryMiB: 4096
disks:
bootVolume:
disk: scsi0
sizeGb: 10
network:
networkDevices:
- name: net0
bridge: vmbr0
model: virtio
vlan: 30
defaultIPv4: true
tags:
- worker
- talos
checks:
skipCloudInitStatus: true
metadataSettings:
providerIDInjection: true
The Worker Talos Config¶
The TalosConfigTemplate is the worker version of the controlPlaneConfig in the TalosControlPlane. For each new
worker, the bootstrap provider generates a Talos config from it with generateType: worker, and applies the
patches on top. Only the install config and the external cloud provider setting are needed, since the VIP and the
CCM itself run on the control plane.
homelab-1/workers-config-template.yaml
apiVersion: bootstrap.cluster.x-k8s.io/v1alpha3
kind: TalosConfigTemplate
metadata:
name: homelab-1-workers
namespace: homelab-1
spec:
template:
spec:
generateType: worker
talosVersion: v1.14.5
strategicPatches:
- |
# The kubelet on every node must run with the external cloud provider,
# otherwise the CCM never sets the provider ID on the workers. Only the
# setting is needed here, the CCM itself runs on the control plane.
cluster:
externalCloudProvider:
enabled: true
---
apiVersion: v1alpha1
kind: UnattendedInstallConfig
installer:
image: factory.talos.dev/nocloud-installer/ce4c980550dd2ab1b17bbf2b08801c7eb59418eafe8f279833297925d67c7515:v1.14.5
provisioning:
diskSelector:
match: disk.dev_path == "/dev/sda"
The Machine Deployment¶
The MachineDeployment ties the worker ProxmoxMachineTemplate and TalosConfigTemplate together and sets the
number of workers. It works like a Deployment, but for machines. It creates a MachineSet, which keeps the number
of Machines at replicas, each one getting a VM from the machine template and a Talos config from the config
template. Like a Deployment, changing a template rolls out new machines and removes the old ones.
homelab-1/workers-machine-deployment.yaml
apiVersion: cluster.x-k8s.io/v1beta2
kind: MachineDeployment
metadata:
name: homelab-1-workers
namespace: homelab-1
spec:
clusterName: homelab-1
replicas: 2
# Like in a Deployment, the selector is how the MachineDeployment finds its
# own Machines. The field is required, but CAPI fills in the labels for both
# the selector and the Machines when it is left empty.
selector: {}
template:
spec:
# Must match spec.clusterName. CAPI checks it, but doesn't fill it in.
clusterName: homelab-1
version: v1.36.5
bootstrap:
configRef:
apiGroup: bootstrap.cluster.x-k8s.io
kind: TalosConfigTemplate
name: homelab-1-workers
infrastructureRef:
apiGroup: infrastructure.cluster.x-k8s.io
kind: ProxmoxMachineTemplate
name: homelab-1-workers
Creating the Cluster¶
Create the namespace, and apply the whole folder to the management cluster. The order of the files doesn’t matter, since CAPI waits for the references to resolve.
Follow along with clusterctl describe, and watch the VMs show up in Proxmox. The control plane comes first, and the
workers are created once the control plane is initialized. It takes a few minutes in total.
NAME REPLICAS AVAILABLE READY UP TO DATE STATUS REASON
Cluster homelab-1/homelab-1 3/3 2 3 2 True Available
├─ProxmoxCluster homelab-1/homelab-1 True InfoReported
├─TalosControlPlane homelab-1/homelab-1, v1.36.5 1/1 1 True NoReasonReported
│ └─Machine homelab-1/homelab-1-plms6, v1.36.5 1 1 1 0 True Ready
└─Workers
└─MachineDeployment homelab-1/homelab-1-workers, v1.36.5 2/2 2 2 2 True Available
└─2 Machines... 2 2 2 True Ready
The control plane is never up to date
Notice the 0 in the UP TO DATE column of the control plane machine. The control plane provider v0.5 doesn’t
implement the newer CAPI v1beta2 contract, so it never sets the UpToDate condition on control plane machines,
and the CP AVAILABLE and CP UP-TO-DATE columns of kubectl get cluster stay empty. It only affects what is
displayed, since TalosControlPlane handles its own rollouts. It is
fixed in v0.6, but that
requires CAPI v1.14, which the Proxmox provider doesn’t support yet.
Accessing the Cluster¶
CAPI stores the kubeconfig of the new cluster as a secret in the management cluster.
NAME STATUS ROLES AGE VERSION INTERNAL-IP OS-IMAGE
homelab-1-cp-4vw6t Ready control-plane 35m v1.36.5 10.0.30.21 Talos (v1.14.5)
homelab-1-workers-bn9dj-cmc6g Ready <none> 27m v1.36.5 10.0.30.22 Talos (v1.14.5)
homelab-1-workers-bn9dj-t8hc7 Ready <none> 27m v1.36.5 10.0.30.23 Talos (v1.14.5)
The node names match the VM names in Proxmox, and the IPs come from the pool. Each node also has the provider ID set
by the CCM, which is what CAPI matched against its Machine.
NAME PROVIDERID
homelab-1-cp-4vw6t proxmox://0d742176-880d-43ef-b0d3-8510039a63c6
homelab-1-workers-bn9dj-cmc6g proxmox://da0f8387-bf88-4ed7-bc08-e58bebf9df13
homelab-1-workers-bn9dj-t8hc7 proxmox://1f537d0b-e252-49a3-8c5e-379e4998a38e
The control plane provider stores the talosconfig as a secret in the management cluster too. KUBECONFIG now
points at the new cluster, so fetch it with the kubeconfig of the management cluster.
The talosconfig works like any other. Use a node IP as the endpoint, not the VIP. The VIP is held through etcd and
moves between control plane nodes, so it can be gone exactly when you need talosctl to fix something.
kubectl --kubeconfig ./management.kubeconfig -n homelab-1 get secret homelab-1-talosconfig \
-o jsonpath='{.data.talosconfig}' | base64 -d > homelab-1.talosconfig
export TALOSCONFIG=./homelab-1.talosconfig
talosctl -e 10.0.30.21 -n 10.0.30.21 health
Both files give full admin access to the cluster, so keep them out of public Git repositories.
Day Two¶
This is where CAPI earns its place. All of the following is done against the management cluster, so point
KUBECONFIG back at it first.
Scaling the workers is a single command. CAPI clones a new VM, and the node joins the cluster on its own.
Scaling down deletes a machine. CAPI drains the node first, then deletes the VM in Proxmox and returns its IP to the pool.
Going to three control plane nodes works the same way, by changing replicas on the TalosControlPlane. The VIP is
already in place, so the endpoint stays the same.
Machines are cattle. CAPI never changes a running VM. Changing the machine template or the Kubernetes version rolls
out new machines and removes the old ones, one at a time. Machine templates can’t be edited in place, so create a new
one, like homelab-1-workers-v2, and point the MachineDeployment at it.
Versions live in more than one place
An upgrade touches several fields that have to move together. The Talos version is in talosVersion and in the
installer image tag, in both the TalosControlPlane and the TalosConfigTemplate. The Kubernetes version is in
version on the TalosControlPlane and the MachineDeployment. A new Talos minor version should also get a new
template with the matching ISO, since the Talos on the ISO has to understand the config before it can install the
new version. Creating the Template shows how to version the templates.
Deleting the cluster deletes every VM and frees every IP. Delete the Cluster resource and let CAPI tear down the
rest in the right order, instead of deleting the files with kubectl delete -f.
Wrapping Up¶
The management cluster takes a bit of work to set up, but after that, a new Talos cluster is a folder of seven
resources and a kubectl apply. The Proxmox provider clones the VMs and hands out the IPs, the Talos providers
generate the configs and bootstrap etcd, and the cluster comes up with a VIP and a cloud controller manager.
Since a cluster is just Kubernetes resources, it can live in Git next to everything else. The natural next step is to let a GitOps tool like Argo CD or Flux apply them.
For a cluster with Cilium and BGP like in
Talos and Cilium with BGP Load Balancing on MikroTik,
the Talos part of that post goes into the strategicPatches. Cilium itself can be installed with a
ClusterResourceSet, or by the GitOps tool once the cluster is up.