ADR-010 took the data, the load balancing, and the secrets to NubeAtlas, and left one question open: how the store is run. Installing it on virtual machines would mean repeating the 38-step checklist somewhere else, with the same result as in March, when the second server ended up with a different version of a library. In this lesson you will learn what a container is and how it differs from a virtual machine, how an image is built with Docker, and how a complete local environment is set up with Docker Compose. You will see why an orchestrator is needed when there are several copies on several machines, and you will get to know the concepts of Kubernetes, the most widespread one. Verdalia will package the store, decide in ADR-011 where to run it, and finally measure scenario QS-2.
What a Container Is
A container is a process that runs isolated from the rest of the system, with its own file system, its own network, and a resource limit. It carries with it everything the application needs: the interpreter, the libraries, and the code. It does not carry a complete operating system: it uses the kernel of the machine it runs on.
| Virtual machine | Container | |
|---|---|---|
| What it virtualizes | An entire machine, with simulated hardware | The environment of a process |
| Operating system | A complete one per virtual machine | Shares the host machine's kernel |
| Typical size | Gigabytes | Tens or hundreds of megabytes |
| Startup | Tens of seconds to minutes | Seconds |
| Isolation | Strong | Weaker: a kernel failure affects all of them |
| Density | Dozens per server | Hundreds per server |
| Typical use | Isolating different systems, or different customers | Packaging and running applications |
They do not compete: in the cloud, containers run inside virtual machines. Remember, too, that here “container” has the Docker meaning, and not the one from the C4 model.
The problem they solve is an old one: “it works on my machine.” The store depends on a version of Python, on twenty libraries, and on a system library to talk to PostgreSQL. Installed by hand, each machine is an opportunity for something to differ. With containers, what is tested and what is deployed is the same file, bit for bit.
Image, Layers, Container, and Registry
| Concept | What it is | Analogy |
|---|---|---|
| Image | An immutable template, with the file system and the startup command | A class |
| Container | An image in execution. From one image you get as many as you want | An object |
| Layer | Each build step adds a layer with the files it changes. Layers are shared between images and cached | A commit |
| Registry | The service where images are published and downloaded from | A code repository |
| Tag | The name of a version of the image: store:2027.06.15-a1b2c3d |
A version name |
Layers explain two behaviors. If only the code changes, the last layer is rebuilt and the previous ones are reused, so building takes seconds. And whatever is written in a layer stays in the image forever, even if a later layer deletes it. We will come back to this when talking about secrets.
Everything a container writes to its file system disappears with it. Data that must survive goes outside: to a database, to an object store, or to a volume.
The Store's Dockerfile
A Dockerfile is the recipe Docker uses to build an image. It is the 38-step checklist, written so that a program runs it.
# --- Stage 1: build. Has compilers; does not reach production ---
FROM python:3.13-slim AS build
RUN apt-get update \
&& apt-get install --yes --no-install-recommends build-essential libpq-dev \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /build
COPY requirements.txt .
RUN pip wheel --no-cache-dir --wheel-dir /packages -r requirements.txt
# --- Stage 2: final image. Only what is needed to run ---
FROM python:3.13-slim
RUN apt-get update \
&& apt-get install --yes --no-install-recommends libpq5 \
&& rm -rf /var/lib/apt/lists/* \
&& useradd --system --uid 10001 --no-create-home store
WORKDIR /app
COPY --from=build /packages /packages
RUN pip install --no-cache-dir /packages/*.whl && rm -rf /packages
COPY verdalia/ ./verdalia/
ARG VERSION=development
ENV VERDALIA_VERSION=${VERSION} \
PYTHONUNBUFFERED=1
USER 10001
EXPOSE 8000
CMD ["gunicorn", "--bind", "0.0.0.0:8000", "--workers", "4", "--access-logfile", "-", "verdalia.app:app"]| Instruction | What it does | Why |
|---|---|---|
FROM python:3.13-slim AS build |
Starts from an official Python image, in its lightweight variant, and names the stage | The full variant takes several times more space |
RUN apt-get ..., in stage 1 |
Installs the compiler and the PostgreSQL headers | The psycopg2 adapter is compiled on installation |
COPY requirements.txt . and RUN pip wheel |
Copies only the dependency list and prepares them as packages | As long as the list does not change, this layer comes from the cache |
Second FROM |
Starts a new, clean image | The compilers stay in stage 1 |
libpq5 |
Installs only the library psycopg2 needs to run |
|
useradd and USER 10001 |
Creates an unprivileged user and runs the store as it | Least privilege: if someone compromises the store, they are not an administrator inside the container |
COPY --from=build |
Brings in the packages prepared in stage 1 | |
COPY verdalia/ ./verdalia/ |
Copies the code, last | It is what changes the most: this way fewer layers are invalidated |
ARG and ENV |
Receive the version at build time and leave it in an environment variable | The /health endpoint returns it |
PYTHONUNBUFFERED=1 |
Python writes the logs as soon as they are produced | A container that dies does not take unwritten messages with it |
EXPOSE 8000 |
Documents the port | The same one since Module 4 |
CMD |
The startup command: Gunicorn, a WSGI server, with 4 worker processes | Access logs go to standard output, not to a file |
The two stages form a multi-stage build. Íker's first version, single-stage and with the full Python image, took 1.1 GB. The final one takes 214 MB.
One line changes in verdalia/app.py: VERSION = os.environ.get("VERDALIA_VERSION", "development"). The server name returned by /health is now the container's.
Best Practices and Essential Commands
| Practice | Reason |
|---|---|
| Small images, from a lightweight base | They download faster, and contain fewer programs with vulnerabilities |
| Multi-stage build | Build tools do not reach production |
| No secrets in the image | Whoever has the image has all of its layers. A secret copied and deleted afterward is still there. Secrets arrive at startup, through the environment |
| Immutable version tags | store:2027.06.15-a1b2c3d is always the same image. latest is a different one every day, and makes it impossible to know what is running and what to roll back to |
A .dockerignore file |
Excludes from the build the repository history, the tests, the documentation, and any environment file |
| One main process per container | The store and the notification worker are different containers, which scale separately |
| Pinned dependency versions | Two builds of the same code produce the same image |
Verdalia's tag combines the date and the abbreviated identifier of the change in the repository. Its .dockerignore has five lines: .git, .env*, docs/, tests/, and **/__pycache__/.
| Command | What it does |
|---|---|
docker build --tag store:test . |
Builds the image with the Dockerfile in the current folder |
docker run --publish 8000:8000 --env-file .env.development store:test |
Creates and starts a container, publishes its port, and passes it the environment |
docker ps |
Lists the running containers |
docker logs <container> |
Shows what it has written to standard output |
docker exec -it <container> sh |
Opens a shell inside a running container |
docker images |
Lists the local images |
docker push <image> and docker pull <image> |
Publishes to the registry and downloads from it |
Docker Compose: The Local Environment
The store needs PostgreSQL, Redis, RabbitMQ, and the notification service. Until now, each person installed them on their laptop, and a newcomer spent their first day on it. Docker Compose describes a set of containers in one file and starts them with one command.
# compose.yaml: local development environment. Not used in production
services:
store:
build: .
ports:
- "8000:8000"
env_file: .env.development
environment:
VERDALIA_DB_HOST: postgres
VERDALIA_REDIS_HOST: redis
VERDALIA_RABBITMQ_HOST: rabbitmq
depends_on:
postgres:
condition: service_healthy
rabbitmq:
condition: service_started
worker:
image: registro.nubeatlas.example/verdalia/notification-service:2027.06.08-1c7d9e0
command: ["python", "worker.py"]
env_file: .env.development
environment:
VERDALIA_RABBITMQ_HOST: rabbitmq
depends_on:
- rabbitmq
postgres:
image: postgres:17
environment:
POSTGRES_DB: verdalia
POSTGRES_USER: store_app
POSTGRES_PASSWORD: ${LOCAL_DB_PASSWORD}
volumes:
- postgres_data:/var/lib/postgresql/data
- ./synthetic_data:/docker-entrypoint-initdb.d:ro
healthcheck:
test: ["CMD-SHELL", "pg_isready --username=store_app --dbname=verdalia"]
interval: 5s
retries: 10
redis:
image: redis:7
rabbitmq:
image: rabbitmq:4
volumes:
postgres_data:servicesdeclares five containers. Inside the network Compose creates, each one is reached by its name: the store connects to the hostpostgres.build: .builds the store with the localDockerfile. The others use published images: the official ones for PostgreSQL, Redis, and RabbitMQ, and thenotification-serviceone, which has its own repository.commandreplaces the image's startup command. Thenotification-serviceimage starts the API by default, and here it starts the worker, which is what the store needs for the emails to go out. The API container has been omitted for brevity.env_fileloads the variables from a file that is not in the repository. It only contains local keys, worthless outside the laptop. Even so, they are not written intocompose.yaml: the secret detector does not tell the difference, and neither does habit.environmentsets what is not secret: the host names.${LOCAL_DB_PASSWORD}is replaced by the value of that variable, which Compose reads from a local.envfile, also outside the repository.depends_onwithservice_healthyholds the store back until PostgreSQL accepts connections, according to thehealthcheckcheck.volumesdoes two things: it keeps PostgreSQL's data between starts and loads, the first time, the synthetic data from Module 5. Nobody works with real data.
docker compose up --detach starts everything, and docker compose down stops it. The environment that used to take a day is ready in four minutes. Compose is not for production: it starts containers on one machine, and does not know how to spread them across several or replace the ones that fail.
The Twelve-Factor App
The twelve-factor app methodology gathers twelve practices so that an application deploys well on cloud platforms. Verdalia has been meeting several of them without naming them:
| Factor | What it asks for | In Verdalia |
|---|---|---|
| Config in the environment | What changes between environments arrives through environment variables, not in the code | Done in Module 5: load_config reads the environment since ADR-007 |
| Stateless processes | Any copy can serve any request. State goes to external services | Done in Module 4: sessions and carts in Redis, images in object storage |
| Logs as event streams | The application writes to standard output, and the platform collects them | Pending until today: local files filled up the disk of verdalia-app-03 on March 20 |
| Disposability | Fast startup and graceful shutdown | New: Gunicorn finishes in-flight requests when it receives the stop signal |
| Dev/prod parity | Development, staging, and production are as similar as possible | New: the same image in all three, and the same backing services with Compose |
Modules 2, 4, and 5 were not done with containers in mind. A tidy design makes the changes you do not yet know about cheap.
Why an Orchestrator Is Needed
Docker runs containers on one machine. Production has several, and then the questions appear. On which machine each copy is started. What happens if a machine shuts down. How you know a copy is ready before sending it traffic. How copies are added when the load rises. How you change version without stopping.
An orchestrator answers all of them with one idea: the desired state. You do not give it commands, such as “start a copy.” You declare a goal to it, such as “there must be three copies of this image,” and the orchestrator tirelessly compares what there is with what there should be and corrects the difference. If a copy dies, it replaces it. Nobody tells it.
Kubernetes: Concepts
Kubernetes is the most widespread orchestrator. It is open source, was born at Google, and every major provider offers it managed.
| Concept | What it is |
|---|---|
| Cluster, control plane, and node | The cluster is the set of machines Kubernetes governs. The control plane holds the desired state and decides; in a managed service, the provider operates it. Nodes are the machines that run containers |
| Pod | The minimum unit: one or more containers that share a network and are deployed together. Usually one |
| Deployment | Declares how many copies of a pod there must be, and how they are updated |
| Service | A stable name and address for a group of pods, which come and go. Distributes traffic among them |
| Ingress | The entry rules for HTTP traffic from outside: domains, routes, and certificates |
| ConfigMap and Secret | Configuration delivered to the pods: non-secret and secret. A Secret is encoded by default, not encrypted: you have to enable encryption or integrate it with a secrets manager |
| Namespace | A logical division of the cluster, by environment or by team. Verdalia's manifests are applied in the verdalia namespace |
| Liveness probe | Is the container still alive? If it fails, Kubernetes restarts it |
| Readiness probe | Can it serve traffic right now? If it fails, it stops sending it traffic, without restarting it |
| Resource requests and limits | The request is what the container is guaranteed, and is used to choose a node. The limit is its maximum |
| HorizontalPodAutoscaler | Adjusts the number of copies according to a metric |
| Rolling update and rollback | The pods of the previous version are replaced by those of the new one little by little, waiting for each one to be ready. kubectl rollout undo returns the Deployment to the previous version |
The Store's Manifests
A manifest is a YAML file that declares an object. These three are from the prototype Íker set up in June. The braces are the compact form YAML allows for small blocks:
apiVersion: apps/v1
kind: Deployment
metadata:
name: store
spec:
replicas: 3
selector:
matchLabels: {app: store}
strategy:
type: RollingUpdate
rollingUpdate: {maxUnavailable: 0, maxSurge: 1}
template:
metadata:
labels: {app: store}
spec:
containers:
- name: store
image: registro.nubeatlas.example/verdalia/store:2027.06.15-a1b2c3d
ports:
- containerPort: 8000
envFrom:
- configMapRef:
name: store-config
- secretRef:
name: store-secrets
resources:
requests: {cpu: "1", memory: 2Gi}
limits: {cpu: "2", memory: 4Gi}
readinessProbe:
httpGet: {path: /health, port: 8000}
periodSeconds: 5
failureThreshold: 2
livenessProbe:
httpGet: {path: /health, port: 8000}
initialDelaySeconds: 15
periodSeconds: 10
failureThreshold: 3
---
apiVersion: v1
kind: Service
metadata:
name: store
spec:
selector: {app: store}
ports:
- {port: 80, targetPort: 8000}
---
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: store
spec:
scaleTargetRef: {apiVersion: apps/v1, kind: Deployment, name: store}
minReplicas: 3
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target: {type: Utilization, averageUtilization: 60}| Fragment | What it declares |
|---|---|
replicas: 3 |
The initial desired state. With the autoscaler active, the autoscaler is in charge |
selector and labels |
Labels tie the objects together: the Deployment governs the pods with app: store, and the Service sends them the traffic |
maxUnavailable: 0 and maxSurge: 1 |
When updating, there are never fewer copies than desired, and at most one extra. The new one is created first, and then an old one is retired |
envFrom |
The environment variables come from a ConfigMap and a Secret. The image contains no configuration |
resources |
One core and 2 GB guaranteed. Two cores and 4 GB at most |
readinessProbe |
Calls /health every 5 seconds. After two consecutive failures, the pod stops receiving traffic |
livenessProbe |
After three consecutive failures, the container is restarted. It waits 15 seconds after startup |
| Service | Receives on port 80 and delivers on port 8000 of the pods |
| HorizontalPodAutoscaler | Between 3 and 10 copies, so that average processor usage stays close to 60% of what was requested |
The /health endpoint from Module 4 now has two readers. It should remain a shallow check. If the liveness probe queried the database, a database outage would make Kubernetes restart every copy of the store at once, which turns one failure into two.
An Autoscaler's Decision, in Python
The rule an autoscaler uses to decide fits in one line:
import math
def desired_replicas(current, current_usage, target_usage, minimum=2, maximum=10, tolerance=0.10):
"""An autoscaler's decision: how many replicas there should be."""
ratio = current_usage / target_usage
if abs(ratio - 1) <= tolerance:
return current # near the target: nothing is touched
desired = math.ceil(current * ratio)
return max(minimum, min(maximum, desired))
CASES = [
("Tuesday afternoon", 2, 35),
("Email campaign starts", 2, 85),
("Still rising", 3, 88),
("Near the target", 6, 63),
("Day before Mother's Day", 6, 110),
("Early morning", 4, 6),
]
print(f"{'Situation':30}{'Replicas':>9}{'Usage':>7}{'Desired':>10}")
for situation, current, usage in CASES:
desired = desired_replicas(current, usage, target_usage=60)
print(f"{situation:30}{current:>9}{usage:>6}%{desired:>10}")Output:
Situation Replicas Usage Desired Tuesday afternoon 2 35% 2 Email campaign starts 2 85% 3 Still rising 3 88% 5 Near the target 6 63% 6 Day before Mother's Day 6 110% 10 Early morning 4 6% 2
Explanation:
ratiocompares actual usage with the target. With 85% usage and a 60% target, it is 1.42: 42% more capacity is needed.- The tolerance avoids flapping. At 63%, the difference is 5% and nothing is done. Without it, the system would add and remove copies continuously.
math.ceilrounds up: 2.83 copies is 3. When in doubt, there is spare capacity.maxandminclamp the result between the minimum and the maximum. On a Tuesday afternoon one copy would be enough, but the minimum is 2, one per zone. On the day before Mother's Day 11 would be needed, but the maximum is 10. The maximum protects the bill, and the database.- Usage can exceed 100% because it is measured against what was requested, not against the limit.
A real autoscaler adds two things. It scales up fast and down slowly: it waits several minutes before removing copies, in case the load returns. And it does not count the copies that are still starting. It also has a limitation: it reacts, it does not anticipate. Time passes between the decision and the copy being ready. Before a mass email send, it is a good idea to raise the minimum by hand.
Alternatives to Kubernetes
| Option | What it consists of | For | Against |
|---|---|---|---|
| Managed container service, without Kubernetes: Amazon ECS with Fargate, Azure Container Apps, Cloud Run | You hand over an image and state the size, the number of copies, and the health check. No nodes or cluster in sight | The lowest operational load. Autoscaling and rolling updates included | Less flexible. The service definition is specific to each provider |
| Managed Kubernetes: Amazon EKS, AKS, GKE | The provider operates the control plane. The customer, the nodes and everything they deploy | Standard, portable, and with a huge ecosystem | Many concepts. Frequent version upgrades. Fixed cost of the cluster |
| Self-managed Kubernetes | The team also operates the control plane | Total control | Requires a dedicated team |
| Docker Swarm | The orchestrator included in Docker | Very simple | Little evolution and a small ecosystem |
| Nomad | HashiCorp's orchestrator, for containers and other kinds of workloads | Simpler than Kubernetes | Smaller community. It has to be operated |
| Virtual machines with Docker | Containers started on each machine, with no orchestrator | No new pieces | Distribution, replacement, and scaling become manual again |
The June Review of ADR-001
ADR-001 set a review for June, and it took place on Wednesday, June 16, with the C4 diagrams on the table.
| Review condition | Situation | Met? |
|---|---|---|
| Team of more than 8 people, or several teams | 3 people | No |
| One area with very different capacity needs | The catalog receives most of the traffic, and the cache and the CDN absorb it | No |
| More than 10,000 orders a month | 3,400 in April, the best month in the store's history | No |
Íker raised a reasonable objection: with containers, deploying one more service costs little. Marta agreed, and pointed out that that was never the cost. Containers make deployment cheaper. They do not make it cheaper to split the data between services, or the network calls where there were function calls, or operating seven pieces among three people.
Result: ADR-001 stands. The store remains a modular monolith, with a single independent service. The time reserved for modularizing drops from 30% to 15%, because the dependency blueprint set in Module 2 has been reached. The next review will be in June 2028, or earlier if any condition is met. The review was recorded in docs/adr/reviews.md: an accepted ADR is not rewritten.
ADR-011
Íker spent nine days, June 7 to 17, on a prototype with NubeAtlas's managed Kubernetes service, in staging. It worked. Lucía deployed the same image on the managed container service in one afternoon.
Marta rated the three options with the weights from Module 1. On availability and performance they tie. The differences are in operability, where the managed service gets a 5 and the other two a 2; in cost, where Kubernetes gets a 2; and in security, where the disappearance of the operating system gives the managed service an edge. Kubernetes wins on scalability, with a 5, which weighs 10 out of 100.
ADR-011: Run the store and the notification service on NubeAtlas's managed container service, without adopting Kubernetes
Status: Accepted
Date: 2027-06-23
Participants: Marta decides; Íker and Lucía consulted; Andrés informed.
Context
ADR-010 left undecided how the store and the
notification-serviceare run. Scenario QS-2 asks for capacity to be added in under 15 minutes. There are two deployable pieces, a team of three people, and a limit of €500 a month. The store no longer keeps state and reads its configuration from the environment.Options considered
- A. Virtual machines with autoscaling. Weighted score: 3.45. Each new machine takes about 5 minutes, and its operating system has to be maintained.
- B. Managed container service. Weighted score: 4.05.
- C. Managed Kubernetes. Weighted score: 3.65. The most flexible and portable. The cluster costs €70 a month, plus a minimum of three nodes: about €311 before serving a single customer, versus €119. It exceeds the budget. It requires upgrading the cluster version several times a year.
Decision
We adopt option B. The store runs on replicas of 2 cores and 4 GB, with 4 processes each, spread across two zones: a minimum of 2, a maximum of 10, and a target of 60% processor usage. The
notification-serviceruns on replicas of half a core and 1 GB: one for the API and two workers. Images are published to NubeAtlas's image registry, with immutable tags. Secrets arrive from the secrets manager at startup. The scheduled jobs, which ran only onverdalia-app-01, become scheduled jobs of the service, with the same image. The database, the cache, and the queues do not run in containers: they are managed services.Consequences
Positive:
- There are no operating systems to install or patch. The 38-step checklist disappears.
- A new replica serves traffic in under two minutes.
- The same image runs on the laptop, in staging, and in production.
Negative:
- The service definition is specific to NubeAtlas. The image is not: it follows an open standard and runs on any orchestrator.
- Per core, a replica costs somewhat more than a reserved machine. With high, constant load, it would come out more expensive.
- Fewer possibilities than Kubernetes. It is not possible, for example, to accompany each replica with auxiliary containers.
- The team gains no experience with Kubernetes, which is the industry standard.
Risks:
- A maximum of 10 replicas with 3 connections per process is 120 connections to the database. The managed database's limit is 200.
Review conditions
To be reviewed if the deployable pieces exceed five, if a feature the service does not offer is needed, if the team adds a person dedicated to the platform, or if a change of provider is decided. The prototype's manifests are kept in the repository.
ADR-011 also revises ADR-005, to which it adds automatic adjustment. An orchestrator is not an end in itself. Verdalia needed three things from it, replacing, scaling, and updating without stopping, and it has obtained them from the simplest service that offers them.
QS-2: The Measurement
On Thursday, July 8, five days before the cutover, Lucía repeated the test from Module 4 against the NubeAtlas environment, sized like production: from 40 to 1,000 users in 30 minutes. Nobody touched anything.
| Minute | Users | Processor usage | Replicas | What happens |
|---|---|---|---|---|
| 0 | 40 | 7% | 2 | |
| 11 | 392 | 69% | 2 | The tolerance is exceeded. The autoscaler requests the third |
| 13 | 456 | 80% | 3 | The third receives traffic, and usage drops to 57% |
| 17, 23, and 28 | 584, 776, and 936 | Between 66% and 69% | 3 to 5 | Requests the fourth, the fifth, and the sixth |
| 30 | 1,000 | 71% | 6 | The sixth receives traffic |
| 35 | 1,000 | 59% | 6 | Stable |
| Measure | Result | Target |
|---|---|---|
| Time between the decision and the replica serving | Between 1 minute 35 seconds and 1 minute 50 seconds | Under 15 minutes |
| Downtime | None | None |
| Catalog 95th percentile, with 1,000 users | 570 ms | Under 800 ms |
| Worst 95th percentile during the ramp-up | 730 ms, in minute 12 | Under 800 ms |
| 99th percentile | 1.4 s | Under 2 s |
| Raising the minimum from 2 to 6 by hand | 2 minutes 10 seconds | |
| Human intervention | None |
Scenario QS-2 is met. On April 28, adding a server took 2 hours and 15 minutes of Lucía's work. The test also confirms QS-1 on the new infrastructure. Off season, Lucía expects 2.2 replicas on average, which would cost €88 a month.
Common Mistakes and Tips
- Using the
latesttag. You do not know which version is running or which one to roll back to. - Putting secrets in the image. Not even with
ARG, which stays in the image's history. - Putting the database in containers because everything else is. A stateful store requires volumes, backups, and failover. If there is a managed service, use it.
- Making the liveness probe depend on other services. It turns one failure into a general restart.
- Adopting Kubernetes for the résumé. It is an excellent tool for a problem you may not have.
- Confusing containers with microservices. A monolith packages just as well.
- Practical tip. Before choosing an orchestrator, write down what you need from it. If the list is “replace, scale, and update,” almost any option works, and the simplest should win.
Exercises
Exercise 1: Review This Dockerfile
FROM python:latest
COPY . /app
WORKDIR /app
ENV VERDALIA_DB_PASSWORD=Summer2027
RUN pip install -r requirements.txt
CMD ["python", "-m", "flask", "run", "--host", "0.0.0.0"]Identify at least five defects and propose a fix for each one.
Exercise 2: The Autoscaler
With the lesson's function, and a 60% target, calculate the desired replicas in three situations: 4 replicas at 95%; 8 replicas at 64%; and 3 replicas at 30%. Then explain what would happen if the target were 90%.
Solutions
Solution to Exercise 1
| Defect | Fix |
|---|---|
python:latest: full image and changing version |
python:3.13-slim |
COPY . /app copies everything, including the repository history and the environment files |
A .dockerignore, and copy only what is needed |
| The code is copied before installing the dependencies | Copy requirements.txt first. That way, a code change does not force reinstalling everything |
A secret in ENV |
It stays in the image, visible to whoever downloads it. It must arrive at startup, from the secrets manager. And that password has to be rotated |
| It runs as an administrator | Create a user and declare it with USER |
| Flask's development server | A WSGI server, such as Gunicorn, with several processes |
| No multi-stage | Separate the build from the execution |
Solution to Exercise 2
- 4 replicas at 95%: the ratio is 1.58, and 4 times 1.58 is 6.33. Desired: 7.
- 8 replicas at 64%: the ratio is 1.07, within the tolerance. Desired: 8.
- 3 replicas at 30%: the ratio is 0.5, and 3 times 0.5 is 1.5, which rounds up to 2. It matches the minimum.
With a 90% target fewer replicas would be needed, and the bill would drop. But each one would work almost at its limit, and there would be no headroom to absorb the rise during the almost two minutes it takes for a new replica to arrive. The 60% target is the price of that headroom. Common mistake: setting the target by looking only at cost.
Conclusion
In this lesson you have learned that a container is an isolated process that carries its dependencies with it, and that an image is its immutable template, built in layers. You have seen a multi-stage Dockerfile, the practices that make it secure and small, and a complete local environment with Docker Compose. You have recognized in the twelve factors decisions Verdalia had already made. You have learned that an orchestrator maintains a desired state, and you have met the concepts of Kubernetes: pods, Deployments, Services, probes, resources, and autoscaling. And you have seen that simpler alternatives exist, which for many teams are the right choice.
In Verdalia, the June review kept ADR-001, and ADR-011 chose NubeAtlas's managed container service, without Kubernetes. The store is a 214 MB image that runs on a minimum of two replicas and a maximum of ten. Scenario QS-2 is met: a new replica serves traffic in under two minutes, without anyone intervening.
A lot of manual work remains around it. The network, the database, and the container service itself were created by Lucía with the mouse, in the NubeAtlas console, and there is no way to know whether staging and production are the same. Íker builds the image on his laptop, and publishes it when he remembers to run the tests first. Deployment still depends on whoever knows how to do it. And of the four decisions left pending in Module 1, one is missing: how to deploy without downtime. The next lesson deals with all of it: “Infrastructure as Code and Continuous Delivery (CI/CD).”
