Custom Kubernetes AMIs
Cluster API uses the Kubernetes Image Builder tools. You should use the AWS images from that project as a starting point for your custom image.
The Image Builder Book explains how to build the images defined in that repository, with instructions for AWS CAPI Images in particular.
Operating system requirements
For custom images to work with Cluster API, it must meet the operating system requirements of the bootstrap provider. For example, the default kubeadm bootstrap provider has a set of [preflight checks][kubeadm-preflight-checks] that a VM is expected to pass before it can join the cluster.
Kubernetes version requirements
The pre-built public images are each built to support a specific version of Kubernetes. When using custom images, make sure to match the image to the version: field of the KubeadmControlPlane and MachineDeployment in the YAML template for your workload cluster.
To upgrade to a new Kubernetes release with custom images requires this preparation:
- create a new custom image which supports the Kubernetes release version
- copy the existing
AWSMachineTemplateand change itsami:section to reference the new custom image - create the new
AWSMachineTemplateon the management cluster - modify the existing
KubeadmControlPlaneandMachineDeploymentto reference the newAWSMachineTemplateand update theversion:field to match
See Upgrading workload clusters for more details.
Creating a cluster from a custom image
To use a custom image, it needs to be referenced in an ami: section of your AWSMachineTemplate.
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: AWSMachineTemplate
metadata:
name: capa-image-id-example
namespace: default
spec:
template:
spec:
ami:
id: ami-09709369c53539c11
iamInstanceProfile: control-plane.cluster-api-provider-aws.sigs.k8s.io
instanceType: m5.xlarge
sshKeyName: default
Selecting a custom image by filters
Instead of pinning an explicit AMI id, you can let the provider resolve the AMI at provisioning time from a set of EC2 image filters. When more than one image matches, the most recently created one (by CreationDate) is selected.
apiVersion: infrastructure.cluster.x-k8s.io/v1beta2
kind: AWSMachineTemplate
metadata:
name: capa-image-filters-example
namespace: default
spec:
template:
spec:
ami:
ownerIDs:
- self
filters:
- name: name
values:
- "my-custom-ami-*"
iamInstanceProfile: control-plane.cluster-api-provider-aws.sigs.k8s.io
instanceType: m5.xlarge
sshKeyName: default
When filters is set and ownerIDs is not specified, all AMIs visible to the caller’s credentials are searched, including public AMIs. This can be a security issue if someone is able to publish malicious AMIs that match your filters. To restrict the search to your own account and avoid matching untrusted public images, set ownerIDs to ["self"]. To search AMIs owned by a specific account, set ownerIDs explicitly:
ami:
ownerIDs:
- "123456789012"
filters:
- name: name
values:
- "my-custom-ami-*"
Additional caveats:
-
The AMI is not pinned. The resolved AMI can change as new matching images are published. The effect depends on the resource type:
AWSMachine: the filter is evaluated once, at instance creation. If a newer image appears later, the running instance is not replaced; it continues running its original AMI for its entire lifetime. The new image only applies to instances created after it was published.AWSMachinePool: the filter is re-evaluated on every reconcile loop. When a newer matching image is found, the provider creates a new launch template version and triggers an Auto Scaling Group (ASG) instance refresh, which rolls all nodes in the pool to the new AMI automatically.
Use
ami.idwhen you need a stable, reproducible image. -
Mutually exclusive.
ami.filterscannot be combined withami.id,ami.eksLookupType, or theimageLookupFormat,imageLookupOrg, andimageLookupBaseOSfields. TheimageLookup*fields onAWSClusterorAWSManagedControlPlaneare still accepted but are ignored for machines that useami.filters. -
ami.ownerIDsis used only ifami.filtersis set.imageLookupOrgdoes not apply toami.filters. -
Architecture is implicit. The provider derives the architecture from the instance type and adds it as an implicit filter, so only AMIs matching the instance architecture are considered. You do not need to include an
architecturefilter yourself; doing so may conflict with the inferred value and produce no results.