Linux System Administration and Shell Scripting

Chapter 13
Containers, Cloud and Immutable Linux Operations

Post Graduate Program in Dev Ops
Linux System Administration and Shell Scripting   •   Post Graduate

13. Containers, Cloud and Immutable Linux Operations

Introduction: Linux Beyond the Traditional Server

Linux system administration has moved from the management of individual physical servers toward the operation of highly automated computing environments. A contemporary Linux administrator may work simultaneously with virtual machines, containers, managed cloud services, image registries, orchestration platforms, and hosts designed to be replaced rather than manually repaired. This shift changes not only the tools used by administrators but also the assumptions underlying administration itself.

In a traditional server model, an administrator logs into a long-lived machine, installs packages, edits configuration files, applies patches, and gradually adapts the machine to changing requirements. This is a mutable model: the operating system changes in place. Containers introduce a different unit of deployment, in which an application and its dependencies are packaged into an image and executed in an isolated process environment. Cloud platforms add programmable infrastructure, elastic capacity, identity-based access, and infrastructure defined through code. Immutable and ephemeral operating models go further by treating operating-system instances as replaceable artifacts rather than as machines to be repaired indefinitely.

These models are not interchangeable. Each offers particular benefits and introduces specific risks. Containers do not replace virtual machines in every situation; immutable systems do not eliminate configuration management; and cloud infrastructure does not remove the need for Linux expertise. Effective administration requires an understanding of the layers involved, the boundaries between them, and the operational consequences of each design choice.

Learning Objectives

By the end of this chapter, students should be able to:

1. Distinguish physical machines, virtual machines, containers, and cloud services as operational layers.

2. Explain how Linux namespaces and cgroups provide process isolation and resource control.

3. Describe the roles of container images, registries, runtimes, and orchestration systems.

4. Apply practical methods for operating and securing containers on Linux hosts.

5. Compare mutable, immutable, and ephemeral operating-system models.

6. Evaluate trade-offs involving performance, security, reliability, cost, and operational complexity.

7. Design an appropriate approach for a cloud-based Linux workload.

8. Identify governance, compliance, and professional risks in container and cloud administration.

From Physical Hardware to Cloud Workloads

A useful way to understand modern Linux operations is to view computing as a stack. At the lowest level is physical hardware, including processors, memory, storage, and network devices. A hypervisor may divide that hardware into virtual machines. Each virtual machine has a virtual CPU, memory, disk, and network interface and normally runs its own kernel and operating system. A container runtime, in turn, may execute isolated processes on a virtual or physical Linux host. Above the container are applications, services, and data.

Virtual machines provide strong isolation because each guest system has a separate kernel. They are appropriate when workloads require different operating systems, stronger tenant boundaries, kernel-level customization, or traditional server semantics. Their disadvantages include greater memory and storage overhead and slower startup than processes or containers.

Containers share the host kernel. A container is therefore not a small virtual machine; it is a process, or group of processes, whose view of the system has been restricted and whose resources can be controlled. Containers generally start quickly and permit high workload density, but their security depends on the host kernel, runtime configuration, image provenance, and the privileges granted to the container.

Cloud computing adds a service and management dimension. Infrastructure-as-a-Service provides virtual machines, networks, and storage. Platform-as-a-Service hides more of the operating system and offers application platforms. Container and serverless services abstract still more infrastructure. The administrator’s work moves from manually configuring machines toward defining desired states, policies, identities, images, and automated delivery pipelines.

The Linux Mechanisms Behind Containers

Container technology is built from ordinary Linux kernel mechanisms combined with user-space tooling. Understanding these mechanisms is essential for diagnosing failures and evaluating security claims.

Namespaces: Controlling What a Process Can See

Linux namespaces provide isolated views of system resources. A process in a namespace may see a different set of processes, network interfaces, mount points, host names, or inter-process communication objects from those visible on the host.

Important namespace types include:

  • PID namespace: gives a process its own process-numbering view. A process may appear as PID 1 inside a container while having a different PID on the host.
  • Mount namespace: isolates the process’s view of mounted filesystems.
  • Network namespace: provides separate interfaces, routing tables, ports, and network statistics.
  • UTS namespace: isolates the host name and domain name.
  • IPC namespace: isolates System V IPC objects and POSIX message queues.
  • User namespace: maps user and group identities between the container and host, potentially allowing a process to be root inside the container without being root on the host.

Namespaces limit visibility, not necessarily all capability. A privileged container may still interact with host resources or perform dangerous kernel operations. Consequently, “isolated” should never be interpreted as “automatically secure.”

Cgroups: Controlling What a Process Can Consume

Control groups, commonly called cgroups, organize processes and apply limits or accounting to resources. Administrators can constrain CPU time, memory, block-I/O activity, and the number of processes. Cgroups also support monitoring and can trigger actions when a process exceeds a memory limit.

For example, a container limited to 512 MiB of memory cannot consume unlimited host memory. If its workload exceeds that limit, the kernel or runtime may reclaim memory or terminate a process. Such behavior must be considered in application design: a memory limit is not a substitute for capacity planning, appropriate application settings, or observability.

Modern Linux distributions commonly use cgroup version 2, which provides a unified hierarchy and consistent resource-control model. Administrators should verify which hierarchy is active because runtime configuration, monitoring commands, and orchestration behavior may differ between cgroup versions.

Capabilities, Seccomp, and Mandatory Controls

Traditional Unix privileges divided authority broadly between root and non-root users. Linux capabilities subdivide root authority into more specific permissions, such as changing network configuration, loading kernel modules, or modifying system time. A container should receive only the capabilities required by its workload.

Seccomp, or secure computing mode, filters system calls available to a process. A runtime can apply a profile that blocks system calls rarely required by ordinary applications. Mandatory access-control systems such as SELinux and AppArmor add policy-based restrictions on files, processes, and operations. These controls are complementary: namespaces provide separation of views, cgroups provide resource control, capabilities reduce authority, and seccomp or mandatory access control restrict operations.

Images, Runtimes, and the Container Lifecycle

A container image is a read-only, versioned package containing a user-space filesystem, metadata, and commonly an application plus its dependencies. Images are frequently constructed in layers. A change to a later layer does not require copying all earlier layers, which improves storage efficiency and enables caching.

An image is not the same as a running container. The image is a template; a container is a runtime instance created from that template, with writable state and process configuration. Important image properties include its base distribution, package versions, entrypoint, exposed ports, environment expectations, user identity, and architecture.

A registry stores and distributes images. Public registries are convenient but require careful trust evaluation. A professional organization should use approved registries, scan images for vulnerabilities, control publication rights, retain provenance information, and preferably sign images so that deployment systems can verify their origin.

Container runtimes operate at more than one level. A high-level engine provides commands for building images, creating networks, managing volumes, and starting containers. A lower-level runtime interfaces more directly with the operating system to create namespaces and cgroups. In orchestrated environments, a node agent requests container execution through a standardized interface while the lower-level runtime performs the actual work.

The ordinary lifecycle includes image acquisition, verification, creation of a container filesystem, namespace and cgroup setup, process execution, logging, health monitoring, termination, and cleanup. Operational design must address what happens when the process exits, where logs go, how data persists, and whether the workload can be recreated elsewhere.

Practical Linux Administration of Containers

A basic administrative workflow begins with inspection rather than immediate modification. An administrator should identify the host, runtime, image digest, container identity, mounted volumes, network attachments, resource limits, and effective privileges. Useful commands vary by platform, but tools such as `ps`, `lsns`, `findmnt`, `ip`, `ss`, `journalctl`, `systemctl`, and runtime-specific inspection commands help connect the container view with the host view.

A minimal container should normally run as a non-root user. The image should contain only required packages, and compilers, package caches, credentials, and diagnostic tools should not be included in production images unless justified. Configuration should be injected through controlled environment mechanisms, mounted configuration, or secret-management services rather than hard-coded into image layers.

Persistent data requires deliberate treatment. The writable layer of a container is usually unsuitable for important state because the container may be deleted and recreated. Databases and other stateful services should use managed storage, dedicated volumes, or a storage system designed for the workload. Backups must be tested independently of the container lifecycle.

Logging should be directed to a central system or platform logging service. An administrator who logs only inside the container risks losing evidence when the container is replaced. Monitoring should include application health, restart frequency, CPU and memory usage, filesystem consumption, network errors, and image or deployment versions.

A simplified example illustrates the principle of explicit limits and identity:

```bash

docker run --rm \

--name web-test \

--user 10001:10001 \

--memory 512m \

--cpus 1.0 \

--read-only \

--cap-drop ALL \

-p 8080:8080 \

example/web:2.4

```

The exact syntax is runtime-specific, but the administrative intent is general: assign a stable name, use a non-root identity, constrain resources, reduce writable state, remove unnecessary capabilities, and expose only the required service interface. A read-only root filesystem may require explicit temporary filesystems or writable volumes for legitimate application needs.

Container Security as a Layered Responsibility

Container security begins before execution. An organization should establish trusted base images, maintain them, scan dependencies, prevent secrets from entering build contexts, and record the source and build process of every deployable image. Vulnerability scanning is useful but incomplete: a scanner may report a package that is not exploitable, miss application-level defects, or fail to identify insecure runtime permissions.

At runtime, the host kernel, runtime daemon, socket, network, filesystem, and orchestration control plane must be protected. Access to a privileged container-management socket can be equivalent to administrative control of the host. Exposing such a socket casually to application containers is therefore a serious security error.

Common high-risk configurations include privileged containers, host PID or network namespaces, unrestricted device access, writable host filesystem mounts, excessive Linux capabilities, untrusted images, and containers running as root without a clear reason. Network policy should restrict communication between services, and administrative interfaces should not be exposed directly to the public Internet.

The principle of least privilege is central. Permissions should be reduced at image-build time, deployment time, and host-policy level. Security also requires rapid patching, incident response procedures, audit trails, and tested recovery. Containers improve reproducibility, but they do not remove the need for vulnerability management or host hardening.

Orchestration and the Desired-State Model

A single host can run a small number of containers, but production environments often require scheduling, replication, service discovery, rolling updates, health checks, autoscaling, and policy enforcement. An orchestrator represents desired state—for example, three replicas of a service using a particular image—and continually attempts to make actual state conform to that declaration.

This model changes the administrator’s role. Rather than logging into a node to repair a process, the administrator changes a declarative specification, validates it, and allows the platform to schedule replacement instances. Nodes become less individually important, while image quality, configuration, identity, networking, storage, and observability become more important.

Desired-state systems are not magic. A faulty specification can reproduce failure quickly, and an unhealthy dependency may cause every replacement instance to fail. Safe delivery therefore uses version control, peer review, automated tests, staged deployment, policy checks, and rollback mechanisms. The key operational distinction is between an application that is stateless and replaceable and one that requires carefully coordinated data management.

Mutable, Immutable, and Ephemeral Linux Models

A mutable operating model assumes that a server persists and is changed in place. Administrators patch packages, edit configuration, install agents, and troubleshoot the same instance over time. This model remains practical for specialized systems, legacy applications, development environments, and systems where replacement is difficult. Its central weakness is configuration drift: two supposedly identical servers may differ because of undocumented manual changes.

An immutable model treats the operating-system image as a versioned artifact. Changes are made by building and testing a new image, which is then deployed by replacing the old instance. The running system is not intended to be modified manually. This improves repeatability, simplifies rollback, and makes the deployed state auditable. It also requires strong image pipelines, externalized configuration, reliable data services, and diagnostic practices that do not depend on permanent local changes.

An ephemeral system is designed to have a short or uncertain lifetime. It may be destroyed after a task, replaced after failure, or recreated as part of scaling. Ephemerality is a property of lifecycle, whereas immutability is primarily a property of how changes are made. A system may be immutable but long-lived, or mutable but frequently replaced; the concepts should not be conflated.

The distinction can be summarized as follows:

| Model | Change method | Main strength | Main concern |

|---|---|---|---|

| Mutable | Modify the running instance | Familiar and flexible | Drift and difficult reproduction |

| Immutable | Build and replace | Consistency and rollback | Pipeline and image-management complexity |

| Ephemeral | Replace frequently or automatically | Resilience and elasticity | Requires external state and observability |

In practice, organizations often use a hybrid approach. Immutable worker nodes may run stateful services backed by persistent storage. Cloud virtual machines may be provisioned from images but still receive limited runtime configuration. The correct question is not whether one model is universally superior, but which model best fits the workload, risk profile, regulatory obligations, and operational capability.

Cloud Operations and Infrastructure as Code

Cloud Linux administration depends heavily on identity and automation. Instead of granting broad shell access to every administrator, organizations define roles that permit specific actions on particular resources. Strong authentication, short-lived credentials, key rotation, separation of duties, and detailed audit logs are essential.

Infrastructure as Code expresses networks, virtual machines, security groups, disks, policies, and services in version-controlled files. A change can then be reviewed, tested, planned, and applied consistently. Configuration management tools remain useful for software and service settings, while image builders create standard operating-system artifacts. These tools address different layers and should not be confused.

Cloud cost is also an operational concern. Unused virtual machines, oversized instances, excessive storage snapshots, unnecessary data transfer, and uncontrolled logging can create significant expense. Resource tags, budgets, quotas, lifecycle policies, and capacity reports connect technical administration with financial governance.

Cloud reliability requires attention to failure domains. A service should not depend unknowingly on one virtual machine, availability zone, storage device, or management credential. Backups, restoration tests, health checks, and recovery objectives should be defined before an incident occurs. Automation must be designed so that a failed instance can be replaced without losing essential data or violating security policy.

An Illustrative Case: Modernizing a Payment Reporting Platform

Background

The following is a fictional illustrative case. FinLedger, a growing financial-services company, operated a reporting platform on three manually configured Linux virtual machines. Administrators applied patches through SSH, deployed applications using copied archives, and stored generated reports on local disks.

Situation and Problem

The platform suffered from configuration drift. A deployment that worked on one server failed on another because of different library versions. During a traffic increase at month-end, memory exhaustion caused one server to become unresponsive. Recovery required several hours because the team had no tested replacement procedure. Regulatory auditors also requested evidence of software versions and administrative changes.

Analysis

The team identified four related problems. First, the mutable servers had diverged. Second, application state and generated reports were coupled to local disks. Third, deployment and operating-system changes were performed through undocumented manual steps. Fourth, the organization had no consistent control over image provenance, privileges, or audit records.

Approach and Solution

FinLedger created a minimal, versioned application image using an approved Linux base image. The application ran as a non-root user, used a read-only root filesystem, and received only the network permissions required for its service. Dependencies were locked and vulnerability scanning was added to the build pipeline.

The application was made stateless. Reports were written to managed object storage, while metadata was placed in a managed database with backups and restoration tests. Infrastructure definitions were stored in version control. A deployment platform maintained multiple application replicas and replaced unhealthy instances. Network rules allowed reporting services to reach only the database and storage endpoints they required.

The virtual-machine hosts were rebuilt from a standard image rather than repaired manually. Administrative access was restricted through identity-based roles, multi-factor authentication, and audited sessions. A staged deployment process tested a new image before production release and retained the previous version for rollback.

Outcome

The platform became reproducible: a failed application instance could be replaced without reconstructing it manually. Month-end capacity could be increased through controlled scaling, and auditors could inspect image versions, deployment approvals, and access logs. The solution did not eliminate all operational work. The team still had to patch the base image, monitor storage and database performance, test recovery, and review access policies.

Learning Points

The case demonstrates that containers are most valuable when combined with disciplined lifecycle design. Packaging an unchanged stateful application into a container would not have solved local-disk dependency or configuration drift. The real improvement came from separating application artifacts, configuration, persistent data, infrastructure definitions, and operational identity. It also shows that immutable infrastructure shifts effort toward build pipelines, testing, governance, and observability rather than removing effort altogether.

Challenges, Failure Modes, and Professional Judgement

A frequent mistake is treating a container as a security boundary equivalent to a virtual machine. The shared kernel means that kernel vulnerabilities, runtime flaws, and excessive privileges can have host-wide consequences. Another mistake is building large images containing unnecessary tools and credentials. Large images slow delivery and increase the vulnerability surface.

Administrators may also assume that a container restart is a recovery strategy. Restarting a process does not correct corrupt data, a faulty deployment, a dependency outage, or an exhausted external service. Similarly, autoscaling cannot compensate for a memory leak if new instances reproduce the same defect.

Immutable operations can create diagnostic tension. A replacement model may remove local evidence unless logs, metrics, crash data, and traces are exported centrally. Teams must establish procedures for controlled debugging without turning production systems into permanently modified machines.

Governance includes responsibility for data location, retention, access, licensing, and jurisdiction. Images may contain open-source components with license obligations. Cloud services may process personal or regulated data across geographic boundaries. Administrators must understand organizational policy and applicable law rather than assuming that technical convenience overrides compliance.

Ethically, administrators hold substantial power over systems and data. They should avoid unnecessary access, protect confidential information in logs and backups, document exceptional actions, and disclose security weaknesses through appropriate channels. Automation increases the scale of both good and bad decisions, making review and accountability essential.

Current Directions

Several developments are shaping Linux operations. Rootless containers reduce the need for a privileged runtime and improve isolation in suitable workloads. Confidential-computing technologies seek to protect data while it is being processed, although their operational and performance implications require evaluation. Software supply-chain security is expanding through signed artifacts, provenance attestations, dependency inventories, and policy-based admission controls.

The Linux ecosystem is also moving toward more image-based host operating systems, where updates are delivered as tested system images and rollback is built into the platform. Serverless and managed container services further reduce host administration, but they increase dependence on provider APIs and platform-specific controls. Artificial-intelligence tools can assist with log analysis, anomaly detection, capacity forecasting, and command explanation; however, automated recommendations must be verified because an incorrect remediation can amplify an outage or security incident.

The enduring trend is a movement from imperative repair toward declarative, testable, and replaceable infrastructure. Human judgement remains necessary for architecture, risk acceptance, exception handling, and ethical governance.

Best Practices for Linux Container and Cloud Operations

1. Build small, versioned images from trusted and maintained bases.

2. Pin important dependencies and record image provenance.

3. Run services as non-root users and remove unnecessary capabilities.

4. Apply namespaces, cgroups, seccomp, SELinux or AppArmor, and network policy as layered controls.

5. Never treat a container’s writable layer as reliable persistent storage.

6. Externalize configuration and secrets through approved mechanisms.

7. Centralize logs, metrics, traces, and security events.

8. Define infrastructure and deployment configuration in version control.

9. Test upgrades, rollback, backup restoration, and disaster recovery.

10. Use least-privilege identities and review administrative access regularly.

11. Monitor cost, resource consumption, vulnerability exposure, and service objectives.

12. Prefer replacement over manual repair where immutable or ephemeral operation is intended, while preserving evidence needed for diagnosis.

Chapter Summary

Modern Linux administration spans physical hosts, virtual machines, containers, orchestration platforms, and cloud services. Containers use namespaces to isolate views of resources and cgroups to control resource consumption; capabilities, seccomp, and mandatory access control provide additional security layers. Images are reproducible templates, while runtimes create and manage their execution. Secure operation requires trusted image sources, least privilege, controlled networking, persistent-storage design, centralized observability, and protected management interfaces.

Mutable systems are changed in place and are familiar but vulnerable to drift. Immutable systems are rebuilt and replaced from versioned artifacts, improving consistency and rollback. Ephemeral systems are designed for replacement and therefore require externalized state and strong automation. Cloud and container operations depend on identity, infrastructure as code, policy, cost management, and recovery planning. The most effective designs combine technical mechanisms with governance, testing, and professional judgement.

Key Terms

Container: An isolated group of processes sharing the host kernel.

Virtual machine: A software-defined computer that runs a guest operating system through a hypervisor.

Namespace: A Linux kernel mechanism that gives processes an isolated view of selected system resources.

Cgroup: A Linux mechanism for organizing processes and controlling or accounting for resource use.

Container image: A versioned, usually read-only package used as the template for a container.

Container runtime: Software that creates and executes containers using Linux isolation mechanisms.

Registry: A service that stores and distributes container images.

Image layer: A reusable filesystem change contributing to a container image.

Linux capability: A discrete privilege separated from the broad traditional root privilege.

Seccomp: A mechanism for restricting the system calls a process may execute.

Rootless container: A container operated without requiring the runtime or container process to have host-root authority.

Orchestrator: A platform that schedules workloads and attempts to maintain their desired state.

Mutable infrastructure: Infrastructure changed directly on running instances.

Immutable infrastructure: Infrastructure updated by building and deploying replacement artifacts.

Ephemeral system: A system intended to have a short or replaceable lifecycle.

Infrastructure as Code: The management of infrastructure through version-controlled declarative or programmatic definitions.

Configuration drift: Unplanned divergence between systems intended to have the same configuration.

Least privilege: Granting only the permissions required for a task.

Supply-chain security: Protection and verification of software components, build processes, artifacts, and dependencies.

Review Questions

Short Answer Questions

1. What is the relationship between a container image and a running container?

2. How do namespaces differ from cgroups?

3. Why is a container not equivalent to a virtual machine?

4. Define configuration drift and identify one cause of it.

5. Why should important application data normally be externalized from a container’s writable layer?

Long Answer Questions

1. Explain the Linux mechanisms that support containers, including namespaces, cgroups, capabilities, and seccomp.

2. Compare mutable, immutable, and ephemeral operating models, including their operational strengths and risks.

3. Describe a secure lifecycle for building, distributing, deploying, and retiring container images.

4. Explain how infrastructure as code and desired-state orchestration change the work of a Linux administrator.

5. Discuss the principal security, governance, and compliance responsibilities involved in cloud-based Linux operations.

Analytical / Application Questions

1. A containerized database loses data whenever its container is recreated. Diagnose the design problem and propose an appropriate storage and backup strategy.

2. An organization wants to run an untrusted workload in a privileged container on a shared production host. Evaluate the risk and recommend a safer architecture.

3. Two supposedly identical cloud servers behave differently after several months of manual administration. Design a migration plan that reduces drift while preserving service availability.

22. Multiple Choice Questions with Answers

Question 1

Which Linux mechanism primarily provides a different view of processes, mounts, or network interfaces to a container?

A. Cgroups

B. Namespaces

C. Image layers

D. Systemd units

Correct Answer: B. Namespaces

Question 2

A container repeatedly consumes all available host memory. Which control is most directly designed to limit this behavior?

A. A registry tag

B. A mount namespace

C. A memory cgroup limit

D. An image signature

Correct Answer: C. A memory cgroup limit

Question 3

Why should a production container generally run as a non-root user?

A. It guarantees that the application cannot fail

B. It reduces the consequences of a process compromise

C. It eliminates the need for image scanning

D. It makes persistent storage unnecessary

Correct Answer: B. It reduces the consequences of a process compromise

Question 4

Which statement best distinguishes an immutable operating model from a mutable one?

A. Immutable systems never receive security updates

B. Mutable systems cannot run containers

C. Immutable systems normally change through replacement of a rebuilt artifact

D. Mutable systems always use physical hardware

Correct Answer: C. Immutable systems normally change through replacement of a rebuilt artifact

Question 5

A team stores database files only in a container’s writable layer. What is the principal operational risk?

A. The container will necessarily use too little CPU

B. The data may disappear when the container is removed

C. The image registry will reject the container

D. The host will be unable to create namespaces

Correct Answer: B. The data may disappear when the container is removed

Question 6

Which practice most directly improves container software supply-chain assurance?

A. Allowing arbitrary public images in production

B. Embedding credentials in image layers

C. Verifying trusted image provenance and scanning dependencies

D. Disabling audit logs to improve performance

Correct Answer: C. Verifying trusted image provenance and scanning dependencies

Question 7

In a desired-state orchestration system, what normally happens when an application replica fails?

A. The desired-state controller attempts to create a replacement

B. The image is permanently deleted

C. All host kernels are recompiled

D. The registry automatically changes the application code

Correct Answer: A. The desired-state controller attempts to create a replacement

Question 8

Which scenario is the clearest example of configuration drift?

A. Two servers are built from the same verified image

B. A service is replaced using a version-controlled deployment

C. Two intendedly identical servers acquire different manually installed packages

D. A container is assigned a memory limit

Correct Answer: C. Two intendedly identical servers acquire different manually installed packages

Question 9

Why is access to a container-management socket potentially dangerous?

A. It only permits viewing application logs

B. It may enable creation of containers with control over the host

C. It disables all network namespaces

D. It prevents image verification

Correct Answer: B. It may enable creation of containers with control over the host

Question 10

Which design best supports an ephemeral application service?

A. Store essential state only on the local container filesystem

B. Require manual edits on each replacement instance

C. Externalize state and use centralized logs and reproducible deployment artifacts

D. Run the service with all capabilities enabled

Correct Answer: C. Externalize state and use centralized logs and reproducible deployment artifacts

Linux System Administration and Shell Scripting
Chapter 13 of 15