Table of Contents
- What Is Mutable Infrastructure?
- What Is Immutable Infrastructure?
- Mutable vs Immutable: A Comparison
- Introducing HashiCorp Packer
- Building Immutable Images with Packer
- References
What Is Mutable Infrastructure?
Mutable infrastructure evolves over time. You maintain a long-lived server, log in to apply patches, and deploy application updates directly on that machine. Workflow:- Update application code.
- Deploy changes to an existing server.
- SSH into the server to install packages or tweak configurations.
Over time, manual patching and ad-hoc changes can lead to configuration drift, causing inconsistencies between environments.
What Is Immutable Infrastructure?
With immutable infrastructure, servers are never modified after they’re deployed. Instead, you build a new server image for every change and replace existing instances. Workflow:- Update application code.
- Build a fresh, fully configured machine image (OS tweaks, dependencies, application artifacts).
- Deploy the new image to replace old instances.
Immutable infrastructure simplifies rollbacks: redeploy a previous image version and your environment reverts instantly.
Mutable vs Immutable: A Comparison
| Feature | Mutable Infrastructure | Immutable Infrastructure |
|---|---|---|
| Deployment Model | Live server updates via SSH | Replace servers with new images |
| Configuration Drift | High risk of drift over time | Zero drift—image contains all configuration |
| Rollbacks | Manual rollback steps | Redeploy previous image |
| Reproducibility | Difficult to reproduce exact state | 100% reproducible builds |
| Tooling Examples | Ansible, Chef, manual scripts | HashiCorp Packer, Terraform, Docker |
Introducing HashiCorp Packer
HashiCorp Packer automates the creation of immutable machine images for multiple platforms:- AWS EC2 AMIs
- Docker containers
- Google Compute Engine images
- Azure Managed Images
- Builders: Base image source (e.g., Ubuntu AMI).
- Provisioners: Steps to install and configure software (Shell, Ansible, Chef).
- Post-processors: Output formats and artifact distribution.
Building Immutable Images with Packer
-
Create a template file (
template.json): -
Run the build command:
- Deploy the resulting AMI via your choice of orchestration: