Imagine you are the author of a book and you need to make changes to an existing edition. When you want to make changes, such as improving the content or fixing the issues and ensuring the book is up to date, you don’t edit the existing book. Instead, you create a new edition with the desired updates while keeping the existing editions intact, like the new edition of this book. Thisconcept aligns with immutable infrastructure.
In IT and systems management, immutable infrastructure is a strategy where, instead of making changes to existing servers or Virtual Machines (VMs), you generate entirely new instances with the desired configuration. These new instances replace the old ones instead of modifying them, like creating a new book edition when you want to incorporate changes.
Here’s how it works:
- Building from scratch: When you need to update a part of your infrastructure, you avoid making direct changes to the existing servers or machines. Instead, you create new ones from a pre-established template (an image) that includes the updated configuration.
- No in-place modifications: Like not editing an existing book, you avoid making in-place modifications to current servers. This practice reduces the risk of unforeseen changes or configuration inconsistencies.
- Consistency: Immutable infrastructure ensures that every server or instance is identical because they all originate from the same template. This uniformity is valuable for ensuring reliability and predictability.
- Rolling updates: When it’s time to implement an update, you systematically replace the old instances with the new ones in a controlled manner. This minimizes downtime and potential risks.
- Scalability: Scaling your infrastructure becomes effortless by generating new instances as needed. This is akin to publishing new book editions when there’s a surge in demand, or things become outdated.
- Rollback and recovery: If issues arise from an update, you can swiftly revert to the previous version by re-creating instances from a known good template.
So, consider immutable infrastructure as a means of maintaining your infrastructure by creating new, improved instances rather than attempting to revise or modify existing ones. This approach elevates consistency, reliability, and predictability within your IT environment.
To understand this further, let’s consider the traditional method of setting up applications via Terraform and Ansible. We would use Terraform to spin up the infrastructure and then use Ansible on top to apply the relevant configuration to the infrastructure. That is what we did in the last chapter. While that is a viable approach, and many enterprises use it, there is a better way to do it with modern DevOps approaches and immutable infrastructure.
Immutable infrastructure is a ground-breaking concept that emerged due to the problems with mutable infrastructure. In a mutable infrastructure approach, we generally update servers in place. So, wefollow a mutable process when we install Apache in a VM using Ansible and customize it further. We may want to update the servers, patch them, update our Apache to a newer version, and update our application code from time to time.
The issue with this approach is that while we can manage it well with Ansible (or related tools, such as Puppet, Chef, and SaltStack), the problem always remains that we are making live changes in a production environment that might go wrong for various reasons. Worse, it might update something we did not anticipate or test in the first place. We also might end up in a partial upgrade state that might be difficult to roll back.
Leave a Reply