πŸŽ‰ 75% of content is free forever β€” Unlock Premium from $10/mo β†’
CW
Search courses…
πŸ’Ό Servicesℹ️ Aboutβœ‰οΈ ContactView Pricing Plansfrom $10

Containerization and Orchestration

InfrastructureCloud Infrastructure🟒 Free Lesson

Advertisement

Infrastructure

Containerization and Orchestration

Containers package applications with their dependencies for consistent deployment. Orchestration platforms like Kubernetes automate scaling, healing, and rolling updates across clusters.

  • Containers β€” Lightweight, isolated application packaging
  • Kubernetes β€” Declarative orchestration at scale
  • Auto-Scaling β€” Dynamic resource adjustment based on load

Containers solved "it works on my machine"; orchestration solved "how do I run 1000 of them."

Containers

A container packages an application with its dependencies into a standardized unit.

DfContainer

A container is a lightweight, standalone, executable unit of software that packages application code together with its dependencies, libraries, and configuration files. Containers share the host OS kernel but run in isolated user spaces, providing better resource efficiency than virtual machines.

Containers vs Virtual Machines

AspectContainerVirtual Machine
IsolationProcess-level (shared kernel)Hardware-level (dedicated kernel)
StartupMillisecondsMinutes
SizeMegabytesGigabytes
Density100s per host10s per host
OverheadMinimalHypervisor overhead
SecurityWeaker (shared kernel)Stronger (full isolation)

Containers use Linux namespaces (PID, network, mount) and cgroups for isolation and resource limits. They share the host kernel, which is why containers are lighter than VMs but have weaker isolation guarantees.

Docker

The de facto standard for building and running containers.

DfDocker

Docker is a platform for developing, shipping, and running applications in containers. Docker images are read-only templates used to create containers. Dockerfiles define how images are built. Docker Compose defines multi-container applications.

Dockerfile example:

Architecture Diagram
FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
EXPOSE 3000
HEALTHCHECK CMD curl -f http://localhost:3000/health
CMD ["node", "server.js"]

Image Layers

Image Size Optimization

sizeimage=βˆ‘layerssize(layer)Β (deduplicated)size_{image} = \sum_{layers} size(layer) \text{ (deduplicated)}

Here,

  • sizeimagesize_{image}=Total image size
  • size(layer)size(layer)=Size of each filesystem layer

Order Dockerfile commands by change frequency: base image β†’ OS packages β†’ dependencies β†’ application code. This maximizes cache hits during rebuilds. Only the changed layer and subsequent layers are rebuilt.

Kubernetes

The industry-standard container orchestration platform.

DfKubernetes

Kubernetes (K8s) is an open-source container orchestration platform that automates the deployment, scaling, and management of containerized applications. It groups containers into pods, manages networking, storage, and provides declarative configuration for desired state management.

Kubernetes ArchitectureControl PlaneAPI ServeretcdSchedulerController MgrCloud Controller ManagerDesired state stored in etcdWorker NodesNode 1kubeletkube-proxyPod A | Pod BNode 2kubeletproxyPod C | Pod DmanagesControl plane manages desired state; worker nodes execute workloads

Key Kubernetes Concepts

ConceptDescription
PodSmallest deployable unit; one or more containers
DeploymentManages replica sets and rolling updates
ServiceStable network endpoint for a set of pods
IngressHTTP routing to services
ConfigMapNon-secret configuration data
SecretSensitive data (passwords, keys)
NamespaceVirtual cluster isolation

Pod Scheduling

DfPod Scheduling

Pod scheduling is the process of assigning pods to nodes based on resource requirements, constraints, and policies. The Kubernetes scheduler considers CPU, memory, affinity/anti-affinity rules, taints/tolerations, and data locality.

Resource Requests

utilization(node)=βˆ‘resources(pods)capacity(node)utilization(node) = \frac{\sum resources(pods)}{capacity(node)}

Here,

  • utilization(node)utilization(node)=Resource utilization of a node
  • resources(pods)resources(pods)=Sum of resource requests of all pods
  • capacity(node)capacity(node)=Total allocatable resources

Scheduling Constraints

ConstraintDescription
Resource requestsMinimum CPU/memory required
Node affinityPrefer/require specific node labels
Pod affinityCo-locate pods on same node
Pod anti-affinitySpread pods across nodes/zones
Taints/TolerationsReserve nodes for specific workloads

Auto-Scaling

DfHorizontal Pod Autoscaler

The Horizontal Pod Autoscaler (HPA) automatically scales the number of pod replicas based on observed metrics (CPU, memory, custom metrics). HPA adjusts replicas to maintain target utilization.

HPA Scaling

replicasnew=⌈replicascurrentΓ—current_metrictarget_metricβŒ‰replicas_{new} = \lceil replicas_{current} \times \frac{current\_metric}{target\_metric} \rceil

Here,

  • replicasnewreplicas_{new}=Desired number of replicas
  • replicascurrentreplicas_{current}=Current number of replicas
  • currentmetriccurrent_metric=Observed metric value
  • targetmetrictarget_metric=Target metric value

HPA Calculation

Current: 3 replicas, CPU at 80%, target: 50%

replicas_new = ceil(3 Γ— 80/50) = ceil(4.8) = 5 replicas

The HPA will scale from 3 to 5 pods.

Kubernetes also supports Cluster Autoscaler, which adds/removes nodes from the cluster based on pending pods. Combined with HPA, this provides full auto-scaling: HPA adjusts pod count, Cluster Autoscaler adjusts node count.

Practice Exercises

  1. Design: Design a Dockerfile for a Node.js application that builds in under 30 seconds and produces an image under 100MB. Explain each optimization.

  2. Kubernetes: Write a Deployment manifest for a web app with 3 replicas, resource limits, rolling updates, and a health check endpoint.

  3. Scaling: Your service receives 10,000 QPS. Each pod handles 1,000 QPS with 500m CPU. Design the HPA and Cluster Autoscaler configuration.

  4. Comparison: Compare Kubernetes, Docker Swarm, and Amazon ECS for a small team running 10 microservices. When would you choose each?

Key Takeaways:

  • Containers package applications with dependencies for consistent deployment
  • Docker provides the standard for building and running containers
  • Kubernetes automates orchestration: scheduling, scaling, healing, rolling updates
  • Pods are the smallest deployable unit; Deployments manage replica sets
  • HPA scales pods based on metrics; Cluster Autoscaler scales nodes
  • Use multi-stage builds and layer ordering to optimize Docker images

What to Learn Next

-> Service Mesh Envoy, Istio, and sidecar proxy patterns.

-> CI/CD Pipelines Continuous integration and deployment strategies.

-> Observability Logging, metrics, tracing, and monitoring.

-> Cost Optimization Cloud cost management and right-sizing.

-> Scalability Fundamentals Vertical vs horizontal scaling and capacity planning.

-> Load Balancing Distribution algorithms and L4 vs L7 load balancing.

⭐

Premium Content

Containerization and Orchestration

Unlock this lesson and 900+ advanced tutorials with a Premium plan.

🎯End-to-end Projects
πŸ’ΌInterview Prep
πŸ“œCertificates
🀝Community Access

Already a member? Log in

Need Expert System Design Help?

Get personalized tutoring, project support, or professional consulting.

Advertisement