Immutable Deployments vs Mutable Updates Explained

Mutable updates vs immutable deployments in practice: release steps, rollback, drift, Packer, ASG instance refresh, Kubernetes rollouts, migration.

Aug 19, 2025 - 18:51
Nov 11, 2026 - 05:37
 0  66
TOPICDevOps BasicsPractical guide
Immutable Deployments vs Mutable Updates Explained

A mutable update changes a running server in place: you patch packages, edit configuration and restart services. An immutable deployment never edits a running machine or container. You build a new image, start fresh instances from it, move traffic over and discard the old ones. Immutable releases are repeatable and roll back by redeploying the previous image.

This page is about the mechanics of the two update models: what actually happens during a release, what each model does to rollback and configuration drift, and how to move from one to the other. For the wider trade-offs of immutable infrastructure, see our post on pros and cons of immutable infrastructure in CI/CD; for the container-specific version, see immutable containers as the secure default.

Key takeaways

  • Mutable updates change a live host with a tool such as Ansible or a package manager. Immutable deployments replace the host or container with a new one built from a versioned image.
  • The immutable release unit is an image (an AMI, a container image or a VM template). The mutable release unit is a set of commands run against machines that already exist.
  • Rollback in the immutable model is a redeploy of the previous image. Rollback in the mutable model means writing and running the reverse changes, which rarely get tested.
  • Configuration drift is the main failure of long-lived mutable servers. Immutable systems limit it because no one is supposed to edit a running instance, and any instance that was edited is replaced at the next release.
  • Immutable does not remove state. Databases, uploads and queues still need persistent storage that lives outside the replaceable instance.
  • Most teams run both models for a while. Moving one service at a time is safer than a platform-wide switch.

Mutable vs immutable at a glance

QuestionMutable updateImmutable deployment
What changes during a release?Files, packages and settings on a running hostNothing on the running host. New hosts or containers replace it
What is the release artifact?A playbook, script or package setA built image with a version or digest
Where does testing happen?Against a staging host that may differ from productionAgainst the exact image that will run in production
How do you roll back?Run reverse steps, or restore from a snapshotPoint the group or Deployment at the previous image
Configuration driftBuilds up over timeLimited, because instances are short lived
Debugging a live faultSSH in and change thingsRead logs and metrics, reproduce from the image, replace the instance
Speed of a one-line changeFastSlower, because you rebuild and roll out an image
Fits bestLegacy hosts, small estates, on-premises databasesAutoscaling groups, Kubernetes, anything that is replaced often

How a mutable update works

In the mutable model the servers are long-lived. A release is a list of changes applied to each of them, usually one batch at a time so the service stays up. The Ansible playbook below upgrades one package and restarts the service on three web hosts at a time.

- name: Patch web tier in place
  hosts: webservers
  serial: 3
  become: true
  tasks:
    - name: Upgrade the application package
      ansible.builtin.apt:
        name: myapp
        state: latest
        update_cache: true

    - name: Restart the service
      ansible.builtin.service:
        name: myapp
        state: restarted

The Ansible documentation describes serial as completing the play on the given number or percentage of hosts before starting the next batch. That batching is what keeps a mutable rollout from taking the whole tier down at once. The state: latest value installs the newest version the repository offers, which is also where the trouble starts: two hosts patched a week apart can end up with different package versions.

Where mutable updates go wrong

  • Hosts that began identical slowly stop matching. One got a hotfix by hand, one missed a playbook run because it was down, one has a different library version from a later repository update.
  • A failed run can leave a host half changed. The playbook may be safe to run again, but the host is in a state nobody tested.
  • The production hosts are never the same as the staging host you validated against, so a passing test does not describe what will happen.
  • Rollback depends on someone having written an undo path, and undo paths are the least rehearsed code in most repositories.

Drift is worth its own look. We cover how to find it in configuration drift detection and infrastructure stability. Detection helps, but the immutable model removes the cause instead of reporting the symptom.

How an immutable deployment works

An immutable release has five steps, whichever platform you use.

  1. Build an image from source and a pinned base. The build runs in CI, not on a server.
  2. Test that image: unit tests earlier in the pipeline, then a smoke test or scan against the built artifact.
  3. Publish it with an identifier you can trace back to a commit, such as a version tag or a content digest.
  4. Start new instances or pods from the image alongside the old ones and wait for health checks to pass.
  5. Shift traffic to the new instances, then terminate the old ones.

Virtual machines: bake an AMI and refresh the group

For virtual machines on AWS the usual tools are Packer to build the image and an Auto Scaling group to replace instances. A minimal Packer template looks like this. The amazon plugin source is github.com/hashicorp/amazon.

packer {
  required_plugins {
    amazon = {
      source  = "github.com/hashicorp/amazon"
      version = ">= 1.2.0"
    }
  }
}

source "amazon-ebs" "app" {
  ami_name      = "myapp-{{timestamp}}"
  instance_type = "t3.micro"
  region        = "ap-south-1"
  source_ami    = "ami-0123456789abcdef0"
  ssh_username  = "ubuntu"
}

build {
  sources = ["source.amazon-ebs.app"]

  provisioner "shell" {
    inline = ["sudo apt-get update", "sudo apt-get install -y myapp"]
  }
}

Replace the placeholder source_ami with a current base image for your region. After the build, create a new launch template version that points to the new AMI, then start an instance refresh. AWS describes an instance refresh as the way to roll out a new AMI across an Auto Scaling group, and the preferences go in a JSON file.

{
  "AutoScalingGroupName": "myapp-web",
  "Preferences": {
    "InstanceWarmup": 60,
    "MinHealthyPercentage": 50,
    "AutoRollback": true
  }
}
aws autoscaling start-instance-refresh --cli-input-json file://config.json

Some defaults matter here. With the CLI, auto rollback is off unless you set AutoRollback to true, and the minimum healthy percentage defaults to 90 percent when the group has no instance maintenance policy. AWS also warns that keeping the default behavior on a one-instance group can cause an outage, because the only instance gets replaced. Instance refresh can also use checkpoints to replace instances in phases so you can verify between batches.

Containers: change the image, let the controller replace pods

On Kubernetes the Deployment controller does the replacement for you. You change the image tag in the Pod template and the controller creates a new ReplicaSet and shifts pods across. By default it keeps at least 75 percent of the desired pods available (25 percent max unavailable) and allows up to 125 percent (25 percent max surge) during the rollout.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp
spec:
  replicas: 4
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0
  selector:
    matchLabels:
      app: myapp
  template:
    metadata:
      labels:
        app: myapp
    spec:
      containers:
        - name: myapp
          image: registry.example.com/myapp:1.8.2
          readinessProbe:
            httpGet:
              path: /healthz
              port: 8080

Setting maxUnavailable: 0 with a readiness probe means a new pod must report ready before an old one is removed. The probe is what makes the rollout safe, so a Deployment without one will route traffic to pods that are not ready. Our post on liveness and readiness probes covers how to write them, and Kubernetes deployment strategies with YAML compares rolling, recreate, blue-green and canary.

Rollback in each model

Rollback is where the two models differ most in practice.

  • Kubernetes: kubectl rollout undo deployment/myapp returns to the previous revision, and --to-revision=2 targets a specific one. The old ReplicaSet already exists, so this is a fast scale change, not a rebuild.
  • Auto Scaling groups: set AutoRollback when starting the refresh, or roll back an in-progress refresh. The group returns to its previous launch template. Auto rollback needs the group to meet AWS's prerequisites, so test it before you rely on it.
  • Mutable hosts: you run a playbook that downgrades the package, restores configuration files and restarts the service. If the failed release also ran a database migration, none of this undoes that, which is true in both models.

Database changes are the exception to every rollback story. Write migrations so the previous application version still works against the new schema (add columns before using them, drop them a release later). Then image rollback is safe. Our post on deployment rollback strategies with commands goes deeper on this.

What cannot be immutable: state and configuration

Immutable servers do not mean immutable data. Treat the replaceable layer and the persistent layer as separate things.

  • Data lives in a managed database, a network volume or an object store. The instance mounts or connects to it and can be destroyed without losing records. For Kubernetes workloads that need stable identity and storage, see when to prefer StatefulSets over Deployments.
  • Environment-specific configuration comes from outside the image: environment variables, a ConfigMap, a parameter store or a mounted file. The same image then runs in staging and production, which is the point of building once.
  • Secrets are injected at start-up from a secrets manager. Baking a credential into an image copies it into every registry, cache and laptop that touches the image.
  • Logs and metrics leave the instance as they are produced. An instance that is about to be replaced should not hold the only copy of anything you need.

Debugging without logging in to fix things

People often object that immutable systems cannot be debugged. They can, but the workflow changes. Read logs and metrics first. If you must look inside a running container, Kubernetes supports ephemeral debug containers through kubectl debug, which add a throwaway container to an existing pod instead of editing the application image. For virtual machines, keep one instance out of rotation for inspection, then replace it. The rule is simple: any change you make by hand is temporary, so write the fix into the image or the build and ship it through the pipeline.

When mutable updates are still the right choice

  • A single on-premises database server where rebuilding means a long restore and a planned window.
  • A vendor appliance or legacy application that cannot be packaged into an image.
  • A very small estate where the cost of an image pipeline is higher than the cost of occasional manual care.
  • Hosts that hold large local state and are expensive to repopulate.

In those cases keep the mutable approach but make it disciplined: run changes through configuration management only, block interactive edits, and schedule a drift check. Our post on how immutable infrastructure improves deployment safety explains the safety argument for the cases where you can switch.

A practical path from mutable to immutable

  1. Pick one stateless service with good health checks. A web or API tier is a good first choice; a primary database is not.
  2. Capture what a server needs today (packages, files, users, services) in code. If you already have Ansible roles, reuse them as the provisioner in your image build.
  3. Build the image in CI and tag it with the commit or version. Stop building on servers.
  4. Move configuration and secrets out of the image so one image works in every environment.
  5. Add health checks and a rolling or blue-green rollout, then practise the rollback until it is routine.
  6. Remove SSH access for routine changes. Keep a break-glass path that is logged and followed by replacement.

Instances that someone changed by hand should be replaced by the next release, not kept. If you want a deeper hands-on route through this workflow, the DevOps course in Pune (Kharadi classroom or live online) covers image builds, Ansible, Kubernetes rollouts and rollback, and the Ansible course covers the configuration-management side.

Common mistakes

  • Using a floating tag such as latest. A rollback to "the previous latest" is ambiguous. Use a version tag or digest.
  • Rebuilding the image per environment. You then test one artifact and ship another.
  • Skipping readiness checks, so a new instance receives traffic before the app has started.
  • Replacing all instances at once. Keep headroom with a minimum healthy percentage or maxUnavailable.
  • Putting state on the root disk of a replaceable instance.
  • Making "temporary" manual fixes and never feeding them back into the build.

Frequently asked questions

What is the difference between immutable and mutable deployments?

A mutable deployment changes existing servers in place with patches and configuration edits. An immutable deployment builds a new image, starts new instances or containers from it, and retires the old ones without ever editing them.

Is immutable always better than mutable?

No. Immutable fits stateless services that are replaced often and that you can package into an image. Mutable updates can be the practical choice for legacy hosts, vendor appliances and databases that are costly to rebuild.

Does a Kubernetes Deployment make my app immutable?

Partly. A Deployment replaces pods when the template changes, which is the immutable pattern. The app is only truly immutable if you also avoid editing running containers, use pinned image tags or digests, and keep configuration outside the image.

How do you roll back an immutable deployment?

Redeploy the previous image. On Kubernetes, kubectl rollout undo deployment/NAME returns to the prior revision. On an Auto Scaling group, roll back the instance refresh or point the group at the previous launch template version.

Where does data go in an immutable setup?

Outside the replaceable instance, in a managed database, a persistent volume or object storage. The application connects to it at runtime, so replacing the instance does not remove the data.

Do immutable deployments cost more?

They can. Rolling out new instances alongside old ones needs temporary extra capacity, and you maintain an image pipeline. Many teams offset this with fewer incidents from drift and faster rollbacks, but the trade depends on your estate.

How is Ansible used in an immutable workflow?

Ansible can still configure the image. Run your roles as the provisioner during the image build, then deploy the finished image. You use the same automation, but it runs once at build time instead of repeatedly on live servers.

Official references

Interested in learning more?Get a callback from our training advisors.

What's Your Reaction?

Like Like 0
Dislike Dislike 0
Love Love 0
Funny Funny 0
Angry Angry 0
Sad Sad 0
Wow Wow 0
Mridul I am a passionate technology enthusiast with a strong focus on DevOps, Cloud Computing, and Cybersecurity. Through my blogs at DevOps Training Institute, I aim to simplify complex concepts and share practical insights for learners and professionals. My goal is to empower readers with knowledge, hands-on tips, and industry best practices to stay ahead in the ever-evolving world of DevOps.