Kubespray
repository·master·Indexed 12 days ago
https://github.com/kubernetes-sigs/kubesprayAn Ansible-based tool for deploying production-ready, highly available Kubernetes clusters across bare metal and cloud providers including AWS, Azure, and GCP. Includes support for offline deployments, Azure Resource Group Templates, and AWS infrastructure provisioning via Terraform.
What's inside Kubespray
- The AWS ALB Ingress Controller automates the provisioning of AWS Application Load Balancers (ALB) to satisfy Kubernetes Ingress resources. It bridges Kubernetes networking definitions with AWS infrastructure.
Understand the Kubespray test case stages
masterKubespray tests are organized into stages that correspond to build pipeline steps. The execution order follows:
unit_tests->part1->part2->part3->special.unit_tests: Covers linting, markdown validation, and Vagrant/Terraform validation.part1: Focuses on Molecule and All-in-One (AIO) tests.part2: Standard tests covering various layouts, Operating Systems (OS), Runtimes, and Network Plugins.part3: Includes upgrade jobs, Terraform jobs, and control plane recovery tests.special: Manual or other miscellaneous jobs.
Manage download and image caching in Kubespray
masterKubespray uses a local cache to speed up subsequent provisioning runs and minimize bandwidth usage.
Local Cache Configuration
When
download_run_onceisTrue, all downloaded files are stored indownload_cache_dir(defaults to/tmp/kubespray_cache).- Disk Usage: Expect approximately 800MB of disk space on the Ansible node for the cache.
- Forcing Cache: If you have a full cache and want to use it without triggering new downloads, set
download_force_cache: True.
Remote Node Cache Management
By default, Kubespray deletes cached images from remote nodes after they are used to save space.
- Keep Remote Cache: Set
download_keep_remote_cache: Trueto prevent deletion. This is useful during development to decrease provisioning times, but increases remote storage requirements from ~150MB to ~550MB (the combined size of all required images).
Configure Kubernetes node topologies
masterYou can define various Kubernetes topologies by specifying the number of hosts for different classes. For each class, you can choose whether or not to allocate floating IP addresses.
Supported host classes:
- Control plane nodes with etcd
- Control plane nodes without etcd
- Standalone etcd hosts
- Kubernetes worker nodes
Important Constraint: The Ansible script will fail if the total number of etcd instances is an even number. This total includes both standalone etcd nodes and etcd replicas deployed within control plane nodes. For example, 3 control plane nodes with etcd + 3 standalone etcd nodes = 6 total etcd instances, which is an invalid configuration.
Customize Kubespray settings using Ansible variables
masterKubespray supports three layers of variable precedence for customization. Use them according to your needs:
- inventory group_vars: The most common method for setting group-level configurations.
- inventory host_vars: Used for host-specific overrides (though
group_varsis usually more practical). - extra vars: Used to override settings via the command line using
ansible-playbook -e @foo.yml.
Warning: Extra vars have the highest precedence and always win. Use them sparingly; they are best for overriding internal Kubespray variables (like those in
roles/vars/). Modifying internal variables is not part of the official Kubespray interface and may cause unexpected breakage if those variables change or disappear in future updates.Provision cloud instances for Kubespray
masterKubespray supports several methods for provisioning the underlying cloud instances before running the deployment playbooks:
- Terraform: Use Terraform to manage infrastructure as code.
- Ansible: Use Ansible modules such as
ec2(for AWS) orgce(for Google Cloud Platform). - Manual Creation: Manually create instances in your cloud environment and then provide their details to Kubespray via the inventory.
Persist cache in the Vagrant Docker image
masterTo maintain a cache between different container runs, mount a local directory to the/root/kubespray_cachepath inside the container using a volume.Compare Kubespray with Kubeadm
masterKubespray and Kubeadm serve different primary functions in the Kubernetes ecosystem, though they are now integrated:
- Kubeadm focuses on Kubernetes cluster lifecycle management (e.g., self-hosted layouts, dynamic discovery). It is essentially a tool for managing the Kubernetes components themselves.
- Kubespray focuses on generic configuration management (the "OS operator" role) and initial cluster bootstrapping, including networking plugins.
Integration Note: Since version v2.3, Kubespray uses
kubeadminternally for cluster creation. This allows Kubespray to leveragekubeadm's lifecycle management expertise while Kubespray handles the underlying OS configuration and infrastructure setup.Flannel supported backends and VXLAN workaround
masterFlannel supports the following backends:
vxlanhost-gwwireguard
VXLAN Workaround: If you encounter issues with the
VXLANbackend, you may need to disable offloading usingethtool. The current workaround is:ethtool --offload flannel.1 rx off tx offMigrate from Docker to Containerd
masterAs of Kubespray 2.18.0,
containerdis the default container engine.Warning: Migrating container engines is not officially supported by Kubespray. While a migration procedure exists, it is not guaranteed to work for all scenarios. The recommended and safest approach is to reset and redeploy the entire cluster with the new container engine.
How the Private Docker Registry addon works
masterThe private registry addon provides a place to store private Docker images within your cluster. It runs as a
Podin thekube-systemnamespace.Because the registry does not currently support SSL or authentication, it would normally trigger Docker's "insecure registry" errors. To bypass this, a proxy is deployed as a
DaemonSeton every node. This proxy exposes port5000on the host via ahostPort. Since Docker accesses the registry vialocalhost:5000, it treats the connection as secure.How the KubeVirt Image Builder works
masterThe KubeVirt Image Builder uses an Ansible playbook to automate the creation of VM disk images for Kubespray CI testing.
The workflow is as follows:
- Downloads upstream cloud images.
- Converts images to
qcow2format. - Resizes the images by adding 8GB.
- Wraps the disk in a Docker image using the
kubevirt/registry-disk-v1alphabase. - Pushes the resulting image to
quay.io/kubespray/vm-<os-name>:<tag>.
Trusted CI jobs can override the target registry for staged publishing using Cloud Build authentication, which bypasses the need for
docker login.# Example of pushing a single image to the staging registry in CI make push-single-staging image_name=ubuntu-2404