Deploying Kubernetes with Kubespray and Ansible

Kubespray uses Ansible playbooks to build Kubernetes clusters on servers you already run. This page covers when it suits an Ansible-standardized team, how to design inventory, network and runtime choices, and the upgrade and etcd work that follows.

On this page

When Kubespray and Ansible fit deploying Kubernetes on your own servers

Kubespray is an Ansible-based installer that builds upstream-style Kubernetes clusters on Linux servers you control, so it suits infrastructure teams that already write, review and run Ansible playbooks. Rather than shipping a proprietary control plane, it uses Ansible roles to prepare hosts, install the container runtime, bootstrap etcd and the control plane, join workers and install a network plugin. Teams that already keep inventories, group variables and vault-encrypted secrets in version control can carry those habits straight into cluster builds, and they can review each change to the cluster as they would any other infrastructure change. The benefit is strongest when the same team also owns the bare metal or virtual machine fleet and wants one automation language across hosts, load balancers and Kubernetes.

The trade-off is that Kubespray leaves more decisions to your team than a packaged distribution does. Your team chooses and tests the Ansible version, the Kubespray release, the Kubernetes version, the CNI plugin and the runtime, and it owns upgrades that run as playbook executions against a live cluster. Confirm with your own engineers whether they can sustain that test-and-promote cycle, because the playbooks are only as dependable as the lab that validates them. If your organization wants an opinionated, immutable node model, a hardened distribution with built-in CIS profiles, or a management plane that handles many clusters for you, a different installer such as RKE2, Talos or Cluster API is usually the better fit. Ask a partner to compare these options against your server estate and staffing before committing.

Choosing Kubespray over kubeadm, RKE2, K3s, Talos or Cluster API

Kubespray is built on Ansible, so it is most natural for teams that already manage their servers with playbooks, roles, inventories and a established review process. Those teams can extend existing automation, reuse their vault and inventory conventions, and keep one operational model for the OS, the network and the cluster. The cost is that Kubespray is a large collection of roles that you configure and maintain yourself, so the team must own the playbook versions and the upgrade tests.

  • Existing skills: Your engineers already read Ansible output and debug failed tasks, which shortens the learning curve.
  • Single automation model: OS hardening, time sync and cluster installation can share one repository and pipeline.
  • Fine-grained control: Variables for the network plugin, runtime and add-ons are set per group, which suits unusual hardware or network designs.
  • Ongoing ownership: Every Kubespray release, Kubernetes version bump and role change needs testing in your own environment.
  • Smaller platform surface: You avoid adopting a second configuration model if your organization has none for infrastructure.

Before choosing this path, check whether your team can run a staging cluster through each upgrade and whether it has someone who will review Kubespray changes regularly.

Inventory, network plugin, runtime and HA options compared

This table compares the main Kubespray configuration choices: inventory groups, network plugin, container runtime and control plane topology with its load balancer. Read each row as a decision: when the option fits your environment, and what to confirm in the Kubespray release you plan to use before you build.

ChoiceWhen it fitsWhat to confirm before building
Inventory groups (etcd, kube_control_plane, kube_node)Teams that want the cluster roles in version-controlled inventory so the same playbooks rebuild or scale the clusterWhich groups the release expects, whether a host may sit in both etcd and control plane groups, and the group variable files it reads
Stacked etcd topologySmaller clusters where fewer hosts and simpler operations matter more than isolating etcd from control plane failuresWhether your Kubespray release places etcd on control plane nodes by default and how it orders etcd member changes during scaling
External etcd topologyEnvironments that want etcd sized, patched and backed up separately from the API serversDedicated etcd hosts, their odd member count, and the backup job you will run against them before the first upgrade
Control plane load balancer on TCP 6443Any multi-control-plane cluster, so kubelets and clients reach a stable address when one API server is downWhether the inventory variables you use configure an internal virtual IP or expect an existing load balancer you provide
Network pluginTeams that already run a CNI standard in their data center and want Kubespray to install that same pluginWhich plugins your release supports, their version pins, and the overlay, encapsulation and policy features you need from it
Container runtimeNodes that must match an existing runtime standard, including registry mirror and cgroup settings your platform team already maintainsWhich runtimes the release supports, the cgroup driver it configures, and how it handles registry mirrors and insecure registries
Offline or private registry imagesAir-gapped or restricted networks where nodes cannot pull images from public registriesWhich image lists the release generates, how you mirror them, and whether the playbooks accept your private registry settings
Playbook upgrade pathTeams that already run Ansible change windows and want upgrades run through the same toolingWhether the release supports your current and target Kubernetes minor versions and the order it upgrades control plane and nodes

How the Kubespray run, inventory and HA control plane fit together

The run starts on an operator workstation, where Ansible reads the inventory and applies Kubespray roles to every host over SSH. Control plane nodes run kube-apiserver behind a TCP load balancer on port 6443, and etcd is either stacked on those nodes or placed in a separate external cluster. Workers join through the same load balancer address. The dashed boundary marks the client network, and the private registry inside it supplies images when the cluster has no internet access. Check that the load balancer address matches the API endpoint in your inventory and that every control plane node can reach the registry.

Kubespray run, inventory groups, HA control plane and private registry inside the client network.

How to run a Kubespray build from inventory to first health check

This sequence takes a set of existing Linux servers from prepared hosts to a verified Kubernetes cluster, with a documented check at each stage so the team knows what the playbook actually produced. Each check is a gate: if it fails, fix that layer before moving on.

  1. Prepare Linux nodes and time sync

    The platform or Linux team prepares every node before Kubespray touches it: supported operating system, consistent kernel and cgroup settings, swap handling, unique hostnames and machine IDs, required ports open between nodes, and time synchronization configured on all hosts. Confirm the exact operating system and kernel requirements in the Kubespray and Kubernetes release notes for the versions you target. Done means every node passes a consistent preflight check, reports the same time source, and can reach every other node on the required ports.

  2. Build the inventory and group variables

    Define the inventory with separate groups for etcd members, control plane nodes and workers, and keep the group variables in version control alongside the cluster name, Kubernetes version and host addressing. Keep etcd and control plane membership deliberate: the HA guidance expects an odd number of etcd members and at least three control plane nodes. Done means the inventory parses with Ansible's inventory listing command and each host resolves to exactly the groups you intended.

  3. Confirm network plugin and runtime settings

    Choose the CNI plugin, the container runtime, the pod and service CIDR ranges, and the kube-proxy mode in the group variables, checking that none of the CIDR ranges overlap with existing networks. Verify that the runtime and cgroup driver match what the kubelet expects for the Kubernetes version you target. Done means a reviewer can point to a written value for each setting, and the ranges have been checked against your routing and firewall design.

  4. Set up the load balancer and private registry

    Place a TCP load balancer in front of the kube-apiserver on port 6443 so clients and nodes use one stable endpoint for the control plane. If the nodes have no internet access, mirror the control plane and add-on images to a private registry and point the Kubespray image variables at it, using kubeadm's image listing as a cross-check. Done means the endpoint answers on port 6443 from every node and a test pull of each required image succeeds from a node with no outbound internet access.

  5. Run the playbook and capture the output

    Run the cluster.yml playbook against the inventory from a controlled admin host, using the same version of Kubespray the team has reviewed, and save the full run log with the inventory and variables used. Treat any failed task as a stop condition and fix the cause before rerunning, since partial runs can leave nodes in mixed states. Done means the play finishes without unresolved failures and the log, inventory and commit reference are stored together for audit and future upgrades.

  6. Verify nodes and system pods

    Retrieve the node list with kubectl and confirm every control plane and worker node reports Ready with the expected Kubernetes version. Then check that the kube-system pods, including the CNI and DNS components, are Running and not restarting. Done means all nodes are Ready and no core system pod is in a crash loop or pending state, which you can confirm with a single listing of the kube-system namespace.

  7. Check etcd member health

    Run etcdctl endpoint health and member list against the etcd members on the control plane nodes, using the certificates Kubespray generated. Confirm the member count matches the inventory and each member reports healthy with a leader in place. Done means every expected member is listed and healthy, and you have taken and stored a first etcd snapshot as part of the backup plan.

  8. Run a test workload and record the first health check

    Deploy a small test workload, such as a deployment with a service, and confirm pods schedule across worker nodes, resolve cluster DNS and respond through the service. Remove the test resources and record the results of every check in one first health check record with the Kubespray and Kubernetes versions. Done means the test workload behaves as expected, and the record becomes the baseline for later upgrades, where the release notes for each target version should be reviewed again.

How Kubespray upgrades and etcd backups fit the version skew policy

The version skew policy sets the order of every Kubespray upgrade. kube-apiserver must move up one minor version at a time and must be upgraded before kube-controller-manager, kube-scheduler and the kubelets. Kubelets may run up to three minor versions older than kube-apiserver, so a team can stage node upgrades across several maintenance windows, but it should not let node versions drift further than the policy allows. Before planning a jump, confirm the current minor version of every component in the inventory, then list the minor steps between it and the target. Kubespray playbooks move the control plane and workers through those steps, so the plan should name each stop and the playbook run that covers it. Read the Kubernetes version skew policy before choosing a target.

The support window determines how far ahead a team needs to plan. The Kubernetes project maintains the three most recent minor releases, and each release receives about one year of patch support. Dates for specific releases change as new minors ship, so confirm the end-of-life date for your version on the releases page before setting an upgrade calendar. Kubespray tracks upstream Kubernetes versions with its own release branches, so the Kubespray version you pin must support both your current and target Kubernetes versions. Verify that compatibility in the Kubespray release notes before you start.

Take an etcd snapshot before any upgrade playbook runs. Use etcdctl snapshot save against a healthy member with the correct TLS certificate paths, then store the file off the control plane nodes. Restoring is a separate skill that the team should rehearse on a non-production copy: restore the snapshot with etcdutl into a fresh data directory, bring up a test control plane, and confirm that the API returns the expected objects. A backup that has never been restored is an assumption, not a recovery plan. Record the snapshot name, etcd version and Kubernetes version in the change record so that a rollback decision can be made quickly.

Security settings to decide during a Kubespray build

Kubespray gives you a working cluster quickly, but the security defaults it lays down are a starting point. The decisions below cover how the API server trusts users, how Secrets are protected, how workloads are constrained, and how the Ansible control path itself is guarded. Settle them in your inventory and group variables before the first playbook run, so the cluster you hand to security review matches what was designed.

Secrets encryption at rest in etcd

Kubernetes stores Secrets unencrypted in etcd by default, so anyone who can read etcd snapshots or disks can read every Secret. Decide whether an encryption configuration for the API server will be enabled during the build, which key provider backs it, and how keys rotate. Confirm the variable names your Kubespray release uses for encryption at rest, and verify with a test Secret that the stored value in etcd is not readable in plain text. Also plan how etcd snapshots are protected, because backups carry the same Secrets.

Secrets good practices

Authentication methods for users

Kubernetes does not manage user accounts as API objects. It accepts X.509 client certificates, bearer tokens including OpenID Connect and JWT, webhook token authentication, or an authenticating proxy. Choose one primary path for people, usually OIDC through your identity provider, and decide whether X.509 certificates remain only for break-glass administrators. Document which methods are enabled on the API server, because each one is a separate trust path that auditors will ask about.

Authentication docs

Pod Security Admission per namespace

Pod Security Standards define three levels: Privileged, Baseline and Restricted. The built-in Pod Security Admission controller enforces them per namespace through labels. Decide which levels apply to system namespaces, platform add-ons and tenant workloads, and whether to start with warn and audit modes before enforcing. Note that some add-ons, such as storage or CNI agents, may need Privileged, so list those exceptions explicitly rather than loosening the default.

Standard levels
3
Pod Security Standards

CIS Kubernetes Benchmark alignment

The CIS Kubernetes Benchmark is a consensus configuration guide that many assessors use as a reference. Decide which benchmark version and profile the build will target, then run a scan against the cluster after installation and record each deviation with its reason. Kubespray exposes many hardening options, so confirm which ones your release sets by default and which you must enable. Treat the scan output as evidence for review, not as proof of compliance.

CIS Kubernetes Benchmark

Least-privilege Ansible access to nodes

Kubespray runs over SSH with privilege escalation, so the controller account often holds root on every node. Create a dedicated automation user with a scoped sudo policy, key-based login from a restricted control host, and separate credentials per environment. Decide whether the playbooks run from a hardened jump host with session logging. Ask your team to confirm which commands the sudo policy must allow, since over-broad rules become the easiest path to cluster-wide compromise.

Protecting inventory and vault secrets

The inventory, group variables and Ansible Vault files hold node addresses, certificate settings and credentials that the playbooks need. Decide where the vault password lives, who can read it, and how it is rotated. Keep the inventory and encrypted variables in version control with review on changes, and never commit the vault password or decrypted files. Confirm that CI runners and developer laptops do not keep long-lived copies of the decrypted values.

Questions buyers ask before choosing Kubespray or a partner

How much effort does Kubespray take compared with a managed Kubernetes service?

Kubespray moves effort from the cloud provider to your team. A managed service handles the control plane, upgrades and much of the node lifecycle for a fee, while Kubespray runs on servers you already operate and leaves those jobs with you. The effort is mostly one-time build work plus recurring operations: owning the inventory, the Ansible code, node patching, etcd backups, certificate handling and each Kubernetes upgrade. Costs come from engineer time, the hardware or virtual machines you fund, and any support contract. Ask a partner to separate one-time build effort from the recurring monthly or quarterly effort, and to state which tasks they will hand over to your team and which they will keep running.

How long does a first Kubespray build take and what drives the time?

The duration depends mostly on what is already in place before the playbooks run. The main drivers are whether the servers, DNS, load balancer address, network ranges and private registry exist and are reachable, how many control plane and worker nodes you need, whether the cluster must run without internet access, and how many integrations such as identity, storage and monitoring are in scope. Approval cycles for change control and firewall rules often take longer than the playbook run itself. Ask for a written timeline that lists each dependency, the party responsible for it, and the acceptance tests that close the build.

What must our team provide before a Kubespray project starts?

Your team supplies the environment and the people who will own it. The usual list has four parts:

  • Servers or virtual machines for control plane and worker nodes, with supported Linux, time sync and the required ports open
  • Network design: node subnets, pod and service CIDRs, DNS, and a virtual IP or TCP load balancer in front of kube-apiserver on port 6443
  • A private container registry and image mirror if the cluster has no internet access, since kubeadm can pull and use a private registry
  • Ansible skills and an operations owner who can read inventory variables, run playbooks from version control and review changes

Ask the partner to confirm which of these they expect you to supply and which they will build.

Can an internal team run a Kubespray cluster without outside help?

Yes, if the team already runs Ansible and Linux infrastructure and has someone who understands Kubernetes well enough to read cluster health and upgrade notes. Teams that have not operated Kubernetes before usually struggle with etcd health, certificate expiry, kubelet version skew and networking faults, not with running the playbooks themselves. Before deciding, check whether at least two people can run the upgrade path, restore etcd from a snapshot and debug node failures. A partner can close that gap through a fixed-scope build with handover, documentation and tested runbooks, or through a retainer for ongoing support.

How do Kubespray upgrades differ from the first installation?

An installation creates the cluster from a known state, while an upgrade changes a running system that carries workloads and data. Upgrades must follow the version skew policy: kube-apiserver moves one minor version at a time, and kubelets may lag the API server by up to three minor versions. Plan etcd backups before every change, check deprecated APIs in your workloads, drain nodes in sequence and keep a rollback path. Upgrade effort recurs with each Kubernetes minor release, which arrives about three times a year. Ask a partner how they test an upgrade in a staging cluster built from the same inventory before touching production.

What does ongoing support cover after the Kubespray build is handed over?

Ongoing support covers the work that keeps the cluster healthy after go-live. Typical items include applying Kubernetes patch releases, planning and executing minor upgrades, renewing certificates, reviewing etcd backups and restore tests, updating the inventory and Ansible roles, responding to incidents and reviewing access and security settings. Scope, response expectations and hours should be written into the agreement. DeployOpen offers ongoing support, upgrades and continuous testing as retainers, and most engagements are fixed-scope with agreed deliverables. Ask for a named list of included tasks, exclusions such as new integrations, and the process for emergency changes.

When should a team pick Kubespray over kubeadm or a managed service?

Choose Kubespray when your organization already standardizes on Ansible, manages bare metal or virtual machines it controls, and wants the cluster built from the same inventory and roles as other infrastructure. It suits teams that want upstream Kubernetes with configurable network and runtime choices. Kubeadm may suit teams that prefer fewer moving parts and manage their own automation, while a managed service suits teams that want the provider to run the control plane. Compare the tools by who writes and maintains the automation, how often you expect to upgrade, and which skills you already have.

Limits to confirm in your environment before committing to Kubespray

Kubespray ties your cluster to a specific release, operating system set, network plugin and image supply chain. Each of the checks below is cheap to run before procurement and expensive to discover after the cluster carries workloads.

Kubespray release matches your Kubernetes version

Kubespray releases pin a set of Kubernetes versions, and the version you need may not be in the current release. Compare the Kubespray release notes with the Kubernetes minor version you plan to run, and confirm the release you pick still gets fixes. Check the Kubernetes support window on the releases page, because a Kubespray release can lag behind upstream patch support. Ask your team who will own the decision to move to the next Kubespray release.

Kubernetes releases

Supported operating systems and kernels

Kubespray targets a list of Linux distributions and versions, and that list changes between releases. Confirm your OS image, kernel version and cgroup setup appear in the Kubespray support matrix for the release you chose. Also check the container runtime and package sources on your distribution, since a supported OS can still lack a current build of a dependency. Test on one node before you order the rest of the fleet.

CNI plugin works on your network

Kubespray offers several network plugins, and each one places different demands on your switches, MTU, routing and firewalls. Calico in BGP mode, for example, needs peering with your network team, while overlay modes need an MTU that matches your underlay. Confirm the plugin you choose supports your node and pod addressing, and that your firewall allows its encapsulation traffic between nodes. Verify these before the first playbook run.

Air-gapped image and package sourcing

A cluster without internet access needs every image, binary and package staged in your private registry or artifact store before the playbooks run. Kubespray can pull from configured mirrors, but you must confirm which control plane, add-on and CNI images your chosen release references and that each one exists in your mirror. Ask who maintains the mirror, how new patch versions get loaded, and how the process repeats during upgrades.

Conformance of the resulting cluster

Kubespray builds upstream Kubernetes, but a cluster built from it is only conformant if the API behavior and components match the upstream release. The CNCF Certified Kubernetes program runs conformance checks on distributions, and an installer-built cluster is not automatically certified. Ask whether your auditors or application vendors require a certified distribution, and if so, plan to run the conformance tests yourself or choose a distribution that already holds certification.

CNCF conformance program

Your CIS benchmark and compliance scope

Kubespray's defaults do not establish a hardened baseline that matches your compliance scope. Map the CIS Kubernetes Benchmark profile your auditors expect to the playbook variables you set, and record any control you choose not to meet with a documented reason. Ask who maintains that mapping after each Kubespray upgrade, because a release can change defaults that a previous audit depended on.

CIS Kubernetes Benchmark

When an Ansible-standardized team should choose Kubespray

Choose Kubespray when your team already runs Ansible as its change system and wants Kubernetes built the same way as the rest of its Linux estate. Roles, inventories, vaulted variables, pull request review and scheduled runs all carry over, so operators do not have to learn a second control plane for node provisioning. The trade-off is that Kubespray becomes a large playbook set you must keep current. Its releases follow Kubernetes minor versions, so each upgrade means reviewing a changed role set, adjusted defaults and component version pins before you run anything against production. A team that treats the playbooks as ordinary infrastructure code, with a test inventory and a staging cluster, absorbs that cost well. A team that copies the repository once and never revisits it does not.

Before committing, confirm which skills and hours you can keep on this work after the first build. Ask whether at least two people can read and modify the playbooks, who owns the fork or vendored copy, how you will track upstream changes, and whether your Ansible version and collection dependencies match what the Kubespray release expects. Check the Kubernetes version you need against the supported minor releases on the Kubernetes releases page, because a cluster that falls out of support forces an upgrade on someone else's schedule. Also decide who signs off on each playbook change, since Kubespray runs can alter etcd membership, certificates and the network plugin.

Between maintaining Kubespray in-house and buying a fixed-scope build with handover, the deciding factor is how much recurring Ansible and Kubernetes work you can staff. In-house maintenance costs engineering time every release cycle, plus the time to rehearse upgrades. A fixed-scope build with handover moves the first build, documentation and inventory design into a written scope with agreed deliverables, leaving your team to run it. Ask any provider for the inventory layout, the playbook version pinning, the upgrade runbook, the etcd backup and restore test, and the handover sessions included in the quote, and ask what support or retainer work is priced separately. A provider does not replace your own on-call knowledge, so budget for your team to take part in the build.

How DeployOpen scopes, builds and supports Kubespray clusters

DeployOpen plans, implements and documents self-hosted Kubespray clusters inside your own servers, data centers or air-gapped networks. Each engagement starts with a written scope that fixes the inventory, network plugin, runtime, control plane layout and upgrade approach before any playbook runs against your hosts.

How we scope

  • Agree in writing which Linux hosts, networks and control plane layout the Kubespray build covers
  • Record the chosen CNI plugin, container runtime and HA load balancer design before work starts
  • Define which Ansible roles, inventory groups and variables your team will own after handover

How we build

  • Structure the Ansible inventory and group variables so cluster changes stay reviewable in your version control
  • Run Kubespray in a staging environment that mirrors your production hosts before touching live nodes
  • Test etcd snapshot creation and restore on the built cluster, and check control plane failover behavior

How we hand over

  • Deliver documented inventory, playbook run procedures and the upgrade steps specific to your environment
  • Walk your platform and Ansible engineers through day-two tasks such as node addition and removal
  • Provide written records of configuration choices, access paths and open items for your review

How we support

  • Offer ongoing support, upgrades and continuous testing as a retainer after the initial build
  • Plan Kubespray version upgrades and Kubernetes minor version steps against the published skew policy
  • Retest cluster hardening and access settings after significant changes to hosts or playbooks

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.