KCNA — Twelve-Factor Apps

3 minute read

The Twelve-Factor App Methodology

The Twelve-Factor App methodology defines best practices for building modern, cloud-native applications. Understanding how these factors map to Kubernetes is important for the KCNA exam.


What Is Twelve-Factor?

The twelve-factor methodology was created by Heroku co-founder Adam Wiggins. It provides guidelines for building applications that:

  • Are portable across execution environments
  • Are suitable for deployment on cloud platforms
  • Can scale up without significant architecture changes
  • Minimize divergence between development and production

The Twelve Factors

Factor 1: Codebase

One codebase tracked in revision control, many deploys.

  • One repo per application/service
  • Same codebase deployed to dev, staging, production
  • K8s mapping: Each microservice has its own Git repo → its own Deployment

Factor 2: Dependencies

Explicitly declare and isolate dependencies.

  • Never rely on system-wide packages
  • Use a dependency manifest (package.json, requirements.txt, go.mod)
  • K8s mapping: Container images bundle all dependencies — no system assumptions

Factor 3: Config

Store config in the environment.

  • Never hardcode configuration (database URLs, API keys, feature flags)
  • Use environment variables
  • K8s mapping: ConfigMaps and Secrets injected as environment variables or mounted files

Factor 4: Backing Services

Treat backing services as attached resources.

  • Databases, message queues, caches are attached resources
  • Should be swappable without code changes — just change the connection string
  • K8s mapping: Services and ExternalName Services abstract backing service endpoints

Factor 5: Build, Release, Run

Strictly separate build and run stages.

  • Build: Compile code + bundle dependencies → artifact (container image)
  • Release: Combine artifact + config → release
  • Run: Execute the release in the environment
  • K8s mapping: CI/CD pipeline builds image → Helm/Kustomize adds config → kubectl apply runs it

Factor 6: Processes

Execute the app as one or more stateless processes.

  • Processes should be stateless and share-nothing
  • Store session/state data in external backing services (Redis, database)
  • K8s mapping: Pods are ephemeral — any pod can be killed and replaced

Factor 7: Port Binding

Export services via port binding.

  • The app is completely self-contained — it binds to a port and serves requests
  • No reliance on a web server being injected at runtime
  • K8s mapping: Containers expose ports → K8s Services route traffic to them

Factor 8: Concurrency

Scale out via the process model.

  • Scale by running more instances (horizontal scaling), not bigger instances
  • Different process types for different workloads (web, worker, scheduler)
  • K8s mapping: HPA scales pods horizontally based on metrics

Factor 9: Disposability

Maximize robustness with fast startup and graceful shutdown.

  • Processes should start fast and shut down gracefully on SIGTERM
  • Handle in-flight requests before terminating
  • K8s mapping: preStop hooks, terminationGracePeriodSeconds, readiness probes

Factor 10: Dev/Prod Parity

Keep development, staging, and production as similar as possible.

  • Minimize gaps in time, personnel, and tools between environments
  • Use the same backing services everywhere
  • K8s mapping: Namespaces for environments, same manifests with different ConfigMaps

Factor 11: Logs

Treat logs as event streams.

  • Don’t write to log files — write to stdout/stderr
  • Let the platform aggregate and route logs
  • K8s mapping: Containers write to stdout → collected by Fluentd/Fluent Bit → shipped to log backend

Factor 12: Admin Processes

Run admin/management tasks as one-off processes.

  • Database migrations, data fixes run as one-off tasks
  • Use the same codebase and config as the running app
  • K8s mapping: Jobs and CronJobs for one-off and scheduled tasks

Summary Table

# Factor K8s Concept
1 Codebase One repo → one Deployment
2 Dependencies Container images
3 Config ConfigMaps, Secrets
4 Backing Services Services, ExternalName
5 Build, Release, Run CI/CD → Container Image → kubectl apply
6 Processes Stateless Pods
7 Port Binding Container ports, Services
8 Concurrency HPA, ReplicaSets
9 Disposability preStop hooks, graceful shutdown
10 Dev/Prod Parity Namespaces, same manifests
11 Logs stdout → Fluentd → backend
12 Admin Processes Jobs, CronJobs

KCNA Exam Tips

  • You don’t need to memorize all 12 factors by number, but know the key principles
  • Focus on factors most relevant to Kubernetes: Config (3), Processes (6), Concurrency (8), Disposability (9), Logs (11)
  • Understand the mapping between twelve-factor principles and Kubernetes objects
  • Know that twelve-factor apps are stateless, configurable, and disposable

What’s Next?

Explore serverless computing and Function as a Service (FaaS) — taking cloud-native even further by abstracting infrastructure entirely.

Next: Serverless and FaaS →

Updated: