Course: Cloud Computing Technologies
Authors: Alex Palesandro, Fulvio Risso, Stefano Galantino, Politecnico di Torino
Source: Cloud Native Applications: the 12-Factors App Best Practices, 35 PDF pages (printed slides 1 and 3–36; printed number 2 is absent).
Lecture numbering: 12 records its position in the course notes. The source was supplied in the study session and remains outside the published resources.

Learning route

Having seen how Kubernetes orchestrates containers internally, this lecture moves one layer up to application design: how microservices must be written, packaged, configured, scaled, deployed, and observed so they actually benefit from cloud-native orchestration. Part I (Factors I–V) covers build-time and release-time foundations (single codebase, dependency isolation, environment config, external backing services, and Build/Release/Run with Helm). Part II (Factors VI–IX) covers runtime behavior (statelessness, port binding, horizontal scaling vs. vertical scaling, disposability, and zero-downtime deployment strategies). Part III (Factors X–XII) covers lifecycle parity (CI/CD, GitOps, IaC), stdout log streams with DaemonSet aggregation, and one-off admin tasks (Jobs/InitContainers). Part IV (Observability) explains why traditional black-box checks give way to the three pillars of observability, OpenMetrics, and Prometheus.

Exam priorities

Focus on: distinguishing Factor II (code dependencies in a Dockerfile) from Factor III (env, ConfigMap, Secret, and Downward API fieldRef) and Factor IV (external backing services via K8s Service); the four parts of a Kubernetes release and Helm charts; why sticky sessions break Factors VI, VIII, and IX; the HPC shared-memory exception to horizontal scaling; comparing all six deployment strategies (especially Canary vs. A/B Testing vs. Shadow and why A/B and Shadow need a Service Mesh); Factor X’s three gaps (time, personnel, tools) with CI/CD, GitOps, and IaC/KIND; why kubectl logs is insufficient and how Fluentd/FluentBit DaemonSets aggregate stdout; why one-off DB migrations belong in versioned Jobs rather than main runtime loops or InitContainers; and Observability (3 pillars, 4 OpenMetrics types, and Prometheus pull architecture with Pushgateway and Alertmanager). Tool lists (Jenkins, TravisCI, StackDriver, Minikube) are supporting/familiarity context.

Factors I–V: Codebase, Dependencies, Config, Backing Services, and Releases

Cloud-native applications leverage cloud elasticity, scalability, and automation inside container orchestrators such as Kubernetes, following the 2011 Heroku 12-Factor Manifesto. Keeping one versioned repository (including Dockerfiles and Kubernetes YAMLs), building self-contained multi-stage images (such as FROM golang:1.19 as builder -> FROM scratch), injecting environment-specific config (env, ConfigMap, Secret, and the Downward API), treating databases and storage as network-attached backing services behind Kubernetes Services, and separating Build -> Release -> Run (automated with Kustomize or Helm charts) ensure the exact same artifact moves cleanly across dev, staging, and production. 12-Factor App - Codebase Dependencies Config Backing Services and Releases

Factors VI–IX: Statelessness, Scaling, Disposability, and Deployment Strategies

At runtime, 12-factor processes share nothing and never rely on sticky sessions—externalizing user state to backing services—and export themselves directly via port binding (ClusterIP Service) without external application servers like Tomcat. Horizontal scaling (scale out via one-thread-per-process replicas and HPA, supplemented by VPA and Cluster Autoscaler) avoids single-server limits except in tightly coupled shared-memory HPC workloads. Disposability (“cattle” Pods with LivenessProbe restarts and graceful connection housekeeping) enables safe upgrades across Recreate, Ramped/Rolling, Blue/Green, Canary, A/B Testing, and Shadow strategies—the last two requiring a Service Mesh for fine-grained traffic routing or mirroring. 12-Factor App - Statelessness Scaling Disposability and Deployment Strategies

Factors X–XII: Dev/Prod Parity, Logging Streams, and Admin Tasks

To avoid environment surprises, teams close time, personnel, and tools gaps using declarative CI/CD pipelines, GitOps (ArgoCD, JenkinsX), Infrastructure as Code (Docker/Packer, Terraform + Ansible), and local Kubernetes clusters (Minikube, MicroK8s, KIND). Applications write logs purely to stdout because kubectl logs only reads live containers and loses logs on crash or deletion; production clusters run Fluentd/FluentBit DaemonSets on every node to enrich logs with metadata and forward them to Elasticsearch or Loki. Finally, one-off admin tasks like database schema migrations must be separated from continuous server execution—implemented as versioned Kubernetes Jobs or InitContainers—while still shipping alongside the app release and config they belong to. 12-Factor App - Dev-Prod Parity Logging Streams and One-Off Admin Operations

From Black-Box Monitoring to Observability and Prometheus

Static up/down checks treat applications as black boxes and only detect known failures after they begin. Complex microservices need observability—a superset of monitoring combining Logs, Metrics, and Traces (such as Jaeger dependency graphs) to diagnose unknown issues and root causes. Processes expose instant metrics in the OpenMetrics standard across four types (Counter, Gauge, Histogram, Summary), while Prometheus discovers targets (kubernetes, file_sd), pulls metrics into its TSDB (using Pushgateway for short-lived exit jobs), serves PromQL queries to Grafana/UIs, and pushes alerts via Alertmanager. Observability Metrics and Prometheus

Source map

PDF pagesPrinted slidesTopic
1–31, 3–4Title (Palesandro, Risso, Galantino), cloud-native intro, 12-Factor Manifesto (Heroku, 2011)
4–55–6Factor I (Single Codebase), Factor II (Dependencies + Go multi-stage Dockerfile example)
6–97–9Factor III (Config as Env Var, envar-demo Pod YAML, Downward API fieldRef volume example)
1010Factor IV (Backing services as attached resources, K8s Service & cloud-agnostic APIs)
11–1311–13Factor V (Build, Release, Run; K8s release elements; Kustomize & Helm charts)
14–1514–15Factor VI (Stateless / no sticky sessions), Factor VII (Port Binding + ClusterIP diagram)
16–1716–17Factor VIII (Horizontal vs. Vertical scaling, HPA/VPA/Cluster Autoscaler, HPC exception)
18–1918–19Factor IX (Disposability, LivenessProbe, graceful shutdown, 6-strategy deployment table)
20–2320–23Factor X (3 parity gaps, CI/CD pipeline, Jenkins/CI-aaS, GitOps, IaC, Minikube/MicroK8s/KIND)
24–2624–26Factor XI (stdout streams, kubectl logs path & crash loss, DaemonSet Fluentd/FluentBit, ES/Loki)
2727Factor XII (One-off admin tasks, DB migration, Jobs vs. InitContainers, shared versioning)
28–3228–32Traditional / black-box monitoring vs. Observability, Three Pillars (Logs, Metrics, Traces)
33–3533–35OpenMetrics (/metrics snippet, 4 metric kinds), Prometheus architecture (TSDB, PromQL, Pushgateway, Alertmanager)
3636References (Copyconstruct, Mirantis, 12factor.net, IBM Cloud)

Retrieval questions

  1. Distinguish what belongs in Factor II (Dockerfile), Factor III (ConfigMap/Secret/Downward API), and Factor IV (Service).
    Code libraries and OS binaries go in the Dockerfile (Factor II); environment-specific settings, secrets, and Pod metadata go in ConfigMap/Secret/Downward API (Factor III); databases and caches run externally as attached backing services behind a Kubernetes Service (Factor IV).
  2. Why do A/B Testing and Shadow deployments require a Service Mesh while Rolling, Blue/Green, and Canary work in vanilla Kubernetes?
    Vanilla Kubernetes Services distribute traffic coarsely across Pod replicas, whereas A/B Testing needs targeted condition-based routing and Shadow needs live traffic mirroring without impacting user responses—both requiring a Service Mesh’s fine-grained traffic control.
  3. Why does kubectl logs fail as a sole production logging strategy, and how do Kubernetes clusters solve this?
    kubectl logs streams from a running container via Kubelet and loses logs on crash or Pod deletion; production clusters deploy Fluentd/FluentBit as a DaemonSet on every node to enrich stdout logs with metadata and ship them to Elasticsearch, Loki, or StackDriver.
  4. Why should a database schema migration run as a versioned Kubernetes Job rather than inside the web server’s startup code?
    Running it in the server’s startup code causes concurrent race conditions across replicas and repeats on every Pod restart, whereas a Job runs the migration once per release while still shipping with the matching app image and environment Secrets.
  5. Trace how Prometheus collects metrics from both long-running web Pods and a short-lived batch job.
    Service discovery (kubernetes, file_sd) finds long-running Pods so Prometheus scrapes their /metrics endpoints directly into its TSDB; a short-lived job pushes metrics on exit to Pushgateway, which Prometheus then scrapes.