Ansible vs Kubernetes: Key Differences, and Is Kubernetes Killing Ansible?

Ansible configures machines; Kubernetes runs containers. How they differ, what Kubernetes really replaced, and how production teams use both together.

Short answer

Ansible is an agentless automation tool that configures servers, network devices and cloud resources by running YAML playbooks over SSH when you trigger it. Kubernetes is a container orchestration platform that runs containerised applications and keeps them in the state you declared, restarting, rescheduling and scaling them automatically.

They aren't direct competitors. Kubernetes replaced Ansible for deploying containerised applications. Ansible is still the usual tool for building clusters (for example with Kubespray), preparing and patching nodes, and automating everything outside the cluster. Most production teams use both.

A few years ago I kept noticing the same thing in DevOps and SRE interview write-ups: candidates were grilled on Kubernetes and barely asked about Ansible, Chef or Puppet. Those tools ruled the virtual-machine era. So the question seemed fair: is Kubernetes killing tools like Ansible?

The answer turned out to be more useful than yes or no. Kubernetes did take over one job that Ansible used to do, deploying and running applications, and it left the rest untouched. This guide compares the two side by side, shows where each one fits, and shows how most production teams use them together.

What Ansible actually does

Ansible is an agentless automation tool from Red Hat. You describe tasks in YAML playbooks, list your machines in an inventory, and Ansible connects to each machine over SSH (or WinRM for Windows) to run those tasks in order. Apart from Python on Linux hosts, nothing needs to be installed on the target machines.

  • Push-based and run-once. Ansible makes changes when you run it, then exits. If someone changes a server by hand afterwards, nothing notices until the next run.
  • Idempotent modules. Most modules check the current state first, so running the same playbook twice doesn't make the same change twice.
  • Works on almost anything. Linux and Windows servers, network switches, load balancers, cloud APIs and databases.
- name: Prepare Linux hosts to become Kubernetes nodes
  hosts: k8s_nodes
  become: true
  tasks:
    - name: Load the br_netfilter kernel module
      community.general.modprobe:
        name: br_netfilter
        state: present

    - name: Enable IPv4 forwarding
      ansible.posix.sysctl:
        name: net.ipv4.ip_forward
        value: "1"
        sysctl_set: true

    - name: Install the container runtime
      ansible.builtin.package:
        name: containerd
        state: present

What Kubernetes actually does

Kubernetes is a container orchestration platform. You declare the desired state of your applications as objects, such as a Deployment with three replicas, and the Kubernetes API stores that state. Controllers then work continuously to make the cluster match it.

  • Continuous reconciliation. If a container crashes, the kubelet restarts it. If a node dies, its pods are recreated on healthy nodes (by default after about five minutes). Nobody has to re-run anything.
  • Scheduling. The scheduler decides which node each pod runs on, based on requests, limits, affinity and taints. (How the Kubernetes scheduler actually chooses a node covers this in depth.)
  • Built-in operations. Rolling updates, rollbacks, service discovery, load balancing and autoscaling come with the platform.
  • Containers only. Kubernetes runs workloads packaged as containers. It doesn't configure the operating system underneath, your network gear or anything outside the cluster.
apiVersion: apps/v1
kind: Deployment
metadata:
  name: web
spec:
  replicas: 3
  selector:
    matchLabels:
      app: web
  template:
    metadata:
      labels:
        app: web
    spec:
      containers:
        - name: web
          image: nginx:1.27
          ports:
            - containerPort: 80

Ansible vs Kubernetes: side-by-side comparison

Ansible Kubernetes
Primary job Configure machines and automate IT tasks Run and manage containerised applications
Model Push-based: runs tasks when you trigger it, then exits Declarative API; controllers reconcile continuously
Drift Fixed on the next run Corrected automatically
Unit of work Tasks in a playbook, run against hosts in an inventory API objects (Pods, Deployments, Services) in a cluster
Agent None: connects over SSH or WinRM kubelet and a container runtime on every node
Targets Linux and Windows servers, network devices, cloud APIs Containers on cluster nodes
Scaling and self-healing Not built in Built in (ReplicaSets, restarts, Horizontal Pod Autoscaler)
Format YAML playbooks with Jinja2 templates YAML or JSON manifests, often via Helm or Kustomize

The most important row is the model. Ansible applies changes when you run it. Kubernetes keeps enforcing the state you declared. That one difference explains most of the others.

So, is Kubernetes killing Ansible?

No, but it did take one of Ansible's biggest jobs.

In the VM era, a typical Ansible playbook copied an application onto a fleet of servers, wrote its config files, restarted the service, and then did the same again on every release. For containerised applications, Kubernetes now does that job better. It restarts failed instances, rolls out new versions gradually and scales replicas, all continuously. Teams that moved their applications to Kubernetes stopped using Ansible for application delivery. That is why it shows up less in interviews.

Application delivery to the cluster has largely moved to GitOps tools such as Argo CD and Flux. They watch a Git repository and apply changes continuously, which fits Kubernetes' reconcile model better than a playbook does. (Running both against the same resources causes fights over who owns a field. Server-side apply explains how to stop GitOps and the HPA fighting over replicas.)

What Kubernetes did not replace is everything around and beneath the cluster:

  • preparing the operating system on the nodes: kernel modules, sysctls, the container runtime, users, hardening and patching
  • building the cluster itself on VMs or bare metal
  • configuring network devices, storage arrays and firewalls
  • managing the many workloads that will never run in containers, such as databases on VMs, Windows servers and legacy applications

Ansible is still the default tool for that work. Its role moved down a layer: from deploying the application to managing the infrastructure the application runs on.

How teams use Ansible and Kubernetes together

1. Building the cluster with Kubespray

Kubespray is a Kubernetes SIGs project that installs production-ready Kubernetes clusters using Ansible playbooks. You describe your nodes in an inventory and run one playbook:

ansible-playbook -i inventory/mycluster/inventory.ini cluster.yml -b -v

Kubespray is popular for on-premises and bare-metal clusters, where there is no managed control plane like EKS, GKE or AKS.

2. Preparing and patching nodes

Even on managed Kubernetes, someone has to own the node image or the self-managed nodes. The playbook earlier in this guide is a typical start: kernel modules, sysctls and the container runtime. Ansible can also drain a node, patch it, reboot it and uncordon it, one node at a time.

3. Talking to the Kubernetes API from Ansible

The kubernetes.core collection lets a playbook create and update Kubernetes objects and install Helm charts. That helps when one workflow spans both worlds, for example creating a DNS record, a cloud database and the Kubernetes Secret that points to it.

- name: Apply an application manifest to the cluster
  kubernetes.core.k8s:
    state: present
    src: manifests/deployment.yaml

- name: Install cert-manager with Helm
  kubernetes.core.helm:
    name: cert-manager
    chart_ref: cert-manager
    chart_repo_url: https://charts.jetstack.io
    release_namespace: cert-manager
    create_namespace: true
    release_values:
      crds:
        enabled: true

For applications you deploy over and over, a GitOps tool is usually the better fit. Ansible is better for one-off and cross-system steps.

4. Writing Kubernetes operators in Ansible

The Operator SDK can build an Ansible-based operator. That is a Kubernetes controller whose reconcile logic is an Ansible role. Teams with years of Ansible roles can turn them into operators that run continuously inside the cluster, without rewriting them in Go.

Which one should you use?

Task Best tool
Deploy, update and scale a containerised application Kubernetes, with Argo CD or Flux
Install Kubernetes on VMs or bare metal Ansible (Kubespray)
Kernel settings, container runtime, users and hardening on nodes Ansible (or a pre-built node image)
Rolling OS patching of cluster nodes Ansible: drain, patch, reboot, uncordon
Configure switches, firewalls and load balancers Ansible
Manage databases or applications on plain VMs Ansible
Create cloud networks, VMs and managed clusters Terraform or OpenTofu
One workflow that touches cloud resources and the cluster Ansible with kubernetes.core

Terraform is the third tool that often comes up here. Terraform (or OpenTofu) creates infrastructure, such as networks, VMs and managed clusters, and tracks it in a state file. Ansible then configures it, and Kubernetes runs applications on it. The three are complements, not rivals. If you're choosing an infrastructure-as-code approach for a platform team, see Crossplane vs Terraform.

Key takeaways

  • Ansible configures machines by running tasks over SSH when you trigger it. Kubernetes runs containers and keeps enforcing the state you declared.
  • Kubernetes replaced Ansible for deploying containerised applications. GitOps tools now do most of that job inside clusters.
  • Ansible is still the standard tool for nodes, clusters, network gear and non-container workloads.
  • Most production teams use both: Kubespray or playbooks to build and patch nodes, and Kubernetes plus GitOps to run applications.
  • For a DevOps career, learn Kubernetes deeply, and keep Ansible for the infrastructure layer. They solve different problems.

Final thoughts

"Is Kubernetes killing Ansible?" is the wrong question. Kubernetes changed what Ansible is for. If your applications run in containers, let Kubernetes and a GitOps tool own them, and use Ansible for the machines, clusters and systems underneath.