Sobes.tech
Middle

What is immutable infrastructure?

sobes.tech AI

Answer from AI

Immutable infrastructure is an approach to managing infrastructure where, after a component (such as a server or container) is created, it is never modified. If an update or change is needed, a new component with the required modifications is created, and the old one is destroyed.

Advantages:

  • Predictability: Configuration is always known.
  • Reliability: Eliminates "configuration drift" issues.
  • Simplified scaling: Easy to create identical copies.
  • Simplified rollback: Can quickly revert to a previous version.
  • Enhanced security: Fewer points for potential attacks.

Tools supporting this approach:

  • Docker and Kubernetes for containers
  • Packer for creating VM images
  • Terraform for managing infrastructure as code

Example:

Instead of updating a package on an existing server:

# AVOID THIS WITH IMMUTABLE INFRASTRUCTURE
sudo apt update
sudo apt upgrade some_package

A new server image with the updated package is created, and new VMs are deployed based on this image, replacing the old ones.

# EXAMPLE OF IMMUTABLE INFRASTRUCTURE - CREATING A NEW IMAGE
FROM ubuntu:20.04
RUN apt update && apt install -y some_package

This image is then used by Kubernetes to deploy new pods.

# EXAMPLE OF USING IMMUTABLE INFRASTRUCTURE IN KUBERNETES
apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-app
spec:
  replicas: 3
  selector:
    matchLabels:
      app: my-app
  template:
    metadata:
      labels:
        app: my-app
    spec:
      containers:
      - name: my-app-container
        image: my-repo/my-app-image:new-version # USING THE NEW IMAGE
        ports:
        - containerPort: 80

Immutable infrastructure promotes more reliable and scalable systems.