M6-S1 — Scale with the chart
Section titled “M6-S1 — Scale with the chart”| Module | M6 — Scale and keep the backends healthy |
| After this session you can | Decide what to scale from the metrics, turn on autoscaling the way the chart accepts it, and size the combined pods so they neither starve nor get killed. |
| Time | Facilitated: 37 min · On your own: 37 min |
| Before you start | M5-S1: Prometheus and the release’s metrics. |
| Go deeper | Helm chart: the core values · Helm chart: queue-depth autoscaling · Runbooks: combined-pod autoscaling |
◆ Orientation (1 min) — More pods is not always more capacity
Section titled “◆ Orientation (1 min) — More pods is not always more capacity”Northwind is adding two hundred drivers next quarter, and month-end already makes the search slow. The reflex is to add replicas. But a pod that waits on MongoDB does not get faster with company, and a combined pod with no resource requests cannot be autoscaled at all. This session is about scaling the tier that is actually the bottleneck, in the way the chart accepts.
▤ Concept (4 min) — What to scale, and how the chart lets you
Section titled “▤ Concept (4 min) — What to scale, and how the chart lets you”Find the bottleneck first
Section titled “Find the bottleneck first”| You see | The bottleneck is | Scaling that helps |
|---|---|---|
| A pod’s CPU near its request; latency rising with load | That workload | More replicas of it (autoscaling) |
A pod restarted with OOMKilled | That pod’s memory | A higher memory limit and a matching heap size, not more replicas |
osos_queue_depth growing, indexing CPU high | The indexing workers | More indexing replicas |
osos_queue_depth growing, indexing CPU low, MongoDB busy | MongoDB | MongoDB capacity or indexes (M6-S2); more workers make it worse |
| A RabbitMQ queue growing, its consumer’s CPU low | Consumer concurrency | The service’s config.rabbitmq.concurrency, then replicas |
| Everything slow, gateway pods busy | The gateway | More gateway replicas (and remember its rate limit counts per pod, M3-S2) |
Two workloads are special. The scheduler gains no throughput from extra replicas (its jobs are locked one at a time); run one, or two only for failover. Combined pods carry many applications: one busy application scales all of them, which is why you may give it a pod of its own.
Autoscaling a combined pod
Section titled “Autoscaling a combined pod”Each combined pod has its own block, core.rest and core.data, with autoscaling.enabled,
minReplicas, maxReplicas and CPU and memory targets. An autoscaler target is a percentage of
the pod’s resource request, and the combined pods ship with no requests (resources: {}).
So enabling autoscaling is always a two-value change, and the chart refuses to render one without
the other. It also refuses quoted numbers ("2"), a maximum below the minimum, a minimum below 1, and
no target at all.
Once autoscaling is on, the Deployment no longer sets replicas, so an upgrade never fights the
autoscaler; replicaCount is then ignored.
Sizing memory. Each combined pod runs Node.js with a heap limit (core.<pod>.nodeOptions,
--max-old-space-size). Keep it at about 75 % of the pod’s memory limit: a heap larger than the
limit gets the pod killed before Node.js can collect garbage; a much smaller one wastes the limit. The
chart’s suggested starting points are about 1.5 GiB requested and 2.5 GiB limit for core-rest, and
768 MiB requested and 1.5 GiB limit for core-data; adjust them from kubectl top and your metrics.
Autoscaling the standalone services
Section titled “Autoscaling the standalone services”Standalone services (identity, indexing, notification, websocket and others) have the same
autoscaling block under their own key, and also need resource requests for a percentage target to
mean anything. Four of them, identity, notification, websocket and indexing, can also scale
on the depth of their RabbitMQ queue (autoscaling.queue.enabled). That needs an external-metrics
provider (for example a Prometheus adapter rule over a RabbitMQ exporter): the chart does not
install it. Without one, the autoscaler reports a failed metric and, if you blanked the CPU and
memory targets, cannot scale at all.
Giving one application a pod of its own
Section titled “Giving one application a pod of its own”When one hosted application (say reaction, at month-end) dominates core-rest, add a pod for it:
a new name in core.deployments, a core.<name> block whose appsEnabled is just reaction, and
remove reaction from core-rest’s list. Its Service, queue and database stay the same (M1-S1); it
now scales and is sized on its own. The move creates a new Deployment, so plan it like a release
change, not like a resize: for a moment the application’s Service has no ready pod.
⛏ Lab (25 min) — Autoscale core-rest the way the chart accepts
Section titled “⛏ Lab (25 min) — Autoscale core-rest the way the chart accepts”Goal. An autoscaler on core-rest with requests, limits and a heap size that agree, after seeing
the chart refuse the incomplete version.
Before you start. The release healthy. Autoscalers need resource metrics; kind has none until you install the metrics server.
-
Install the metrics server, and allow it to talk to kind’s kubelet without verified certificates (lab only):
Terminal window kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yamlkubectl -n kube-system patch deployment metrics-server --type=json \-p='[{"op":"add","path":"/spec/template/spec/containers/0/args/-","value":"--kubelet-insecure-tls"}]' -
After a minute, read what the release really uses:
kubectl top pods -n northwind. Note the memory ofcore-restandcore-data. -
Add to
nw-values.yaml, undercore:, an autoscaler without requests:core:rest:autoscaling:enabled: trueminReplicas: 1maxReplicas: 3targetCPUUtilizationPercentage: 80 -
Render:
helm template nw ./osos -n northwind $values > /dev/null. Read the refusal. -
Add requests, a limit and a heap that fits it, under
core.rest:resources:requests:cpu: 250mmemory: 1Gilimits:memory: 2GinodeOptions: "--max-old-space-size=1536"(2 GiB limit × 75 % ≈ 1.5 GiB heap. These are lab sizes, smaller than the production starting points.)
-
Render again; then upgrade:
helm upgrade nw ./osos -n northwind $values --wait --timeout 15m. -
Read the autoscaler:
kubectl -n northwind get hpa. After a minuteTARGETSshows a percentage, not<unknown>. -
Check the Deployment no longer sets its own replica count:
kubectl -n northwind get deploy nw-osos-core-rest -o jsonpath='{.spec.replicas}'shows the autoscaler’s current count, and the rendered Deployment has noreplicas:line (helm get manifest nw -n northwind | grep -A30 'name: nw-osos-core-rest$' | grep replicas). -
In
inventory.md, write what you would change for production, using yourkubectl topfigures.
Check.
- The metrics server answers
kubectl top. - Step 4 failed with a message about the missing request.
- Step 6 rendered and upgraded cleanly.
- The autoscaler shows a resolved CPU percentage.
- The heap size is about 75 % of the memory limit.
Pass condition. All five checks hold.
If something goes wrong
| What you see | What to do |
|---|---|
kubectl top says metrics are not available | Wait a minute; check the metrics server pod is ready and has the --kubelet-insecure-tls argument. |
| Step 6 fails on a quoted number | Write minReplicas: 1, not "1". |
TARGETS stays <unknown> | A metrics problem, not a chart one: check the metrics server, and that the request is set on core.rest, not core.data. |
core-rest restarts with OOMKilled after the change | The lab limit is too low for your use; raise limits.memory to 2560Mi and the heap to 1920. |
| The upgrade waits a long time | Changing a combined pod restarts it; it can take up to 150 seconds to be ready. |
Model answer
Step 4 fails with a message from the chart’s validator naming core.rest and the missing
resources.requests for the CPU target. After step 5 the render passes; the autoscaler shows, for
example, cpu: 12%/80% with MINPODS 1 and MAXPODS 3.
For production, from your kubectl top figures plus headroom, a reasonable first entry is:
core: rest: resources: requests: { cpu: 500m, memory: 1536Mi } limits: { memory: 2560Mi } nodeOptions: "--max-old-space-size=1920" autoscaling: { enabled: true, minReplicas: 2, maxReplicas: 6, targetCPUUtilizationPercentage: 75 }minReplicas: 2 keeps a second pod serving while one restarts, which also helps upgrades.
◇ Worked scenario (1 min) — Month-end search is slow
Section titled “◇ Worked scenario (1 min) — Month-end search is slow”On the last working day, Northwind’s finance team says search results lag by ten minutes. In
Prometheus, max by (queue) (osos_queue_depth) climbs all morning. A colleague has already raised the
indexing replicas from two to six. The backlog grew faster.
Decide: why did more workers make it worse? Look at the indexing pods’ CPU: low. Look at MongoDB: its CPU is saturated and slow-query logs fill with index builds on large collections. The workers are waiting on MongoDB; six of them send it three times the load of two.
Decide: what helps? Scale indexing back to two. Give MongoDB the capacity the month-end needs, or move the heavy rebuilds out of business hours; and check with the vendor whether the slow index builds are expected for that data size. Then confirm with the same query that the backlog drains.
The lesson: scale the tier that is busy. The queue only tells you there is a backlog; the CPU of the workers and of the datastore tells you where it is.
✓ Practice (5 min) — Check your understanding
Section titled “✓ Practice (5 min) — Check your understanding”An operator adds core.data.autoscaling.enabled: true with a CPU target, and the upgrade fails
before anything changes in the cluster. Why?
Check your answer
The correct answer is A. Open the explanation under each option to see why.
core-rest has a 2 GiB memory limit and --max-old-space-size=3072. What happens under load?
Check your answer
The correct answer is B. Open the explanation under each option to see why.
You turned on queue-depth autoscaling for notification and blanked its CPU and memory targets. The
autoscaler never scales and shows <unknown>. What is missing?
Check your answer
The correct answer is B. Open the explanation under each option to see why.
Scheduled reminders sometimes run late. A colleague proposes four scheduler replicas. What do you say?
Check your answer
The correct answer is B. Open the explanation under each option to see why.
↺ Recap (1 min) — Scaling you can justify
Section titled “↺ Recap (1 min) — Scaling you can justify”You can find the tier that is the bottleneck, turn on autoscaling for combined pods and standalone services the way the chart accepts, size memory and heap together, and give a busy application a pod of its own.
Next. In M6-S2 you look after the three datastores themselves: high availability for MongoDB, Redis and RabbitMQ, and the routine upkeep that keeps them healthy.