Skip to content
ModuleM6 — Scale and keep the backends healthy
After this session you canDecide 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.
TimeFacilitated: 37 min · On your own: 37 min
Before you startM5-S1: Prometheus and the release’s metrics.
Go deeperHelm 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”
You seeThe bottleneck isScaling that helps
A pod’s CPU near its request; latency rising with loadThat workloadMore replicas of it (autoscaling)
A pod restarted with OOMKilledThat pod’s memoryA higher memory limit and a matching heap size, not more replicas
osos_queue_depth growing, indexing CPU highThe indexing workersMore indexing replicas
osos_queue_depth growing, indexing CPU low, MongoDB busyMongoDBMongoDB capacity or indexes (M6-S2); more workers make it worse
A RabbitMQ queue growing, its consumer’s CPU lowConsumer concurrencyThe service’s config.rabbitmq.concurrency, then replicas
Everything slow, gateway pods busyThe gatewayMore 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.

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.

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.

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.

  1. 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.yaml
    kubectl -n kube-system patch deployment metrics-server --type=json \
    -p='[{"op":"add","path":"/spec/template/spec/containers/0/args/-","value":"--kubelet-insecure-tls"}]'
  2. After a minute, read what the release really uses: kubectl top pods -n northwind. Note the memory of core-rest and core-data.

  3. Add to nw-values.yaml, under core:, an autoscaler without requests:

    core:
    rest:
    autoscaling:
    enabled: true
    minReplicas: 1
    maxReplicas: 3
    targetCPUUtilizationPercentage: 80
  4. Render: helm template nw ./osos -n northwind $values > /dev/null. Read the refusal.

  5. Add requests, a limit and a heap that fits it, under core.rest:

    resources:
    requests:
    cpu: 250m
    memory: 1Gi
    limits:
    memory: 2Gi
    nodeOptions: "--max-old-space-size=1536"

    (2 GiB limit × 75 % ≈ 1.5 GiB heap. These are lab sizes, smaller than the production starting points.)

  6. Render again; then upgrade: helm upgrade nw ./osos -n northwind $values --wait --timeout 15m.

  7. Read the autoscaler: kubectl -n northwind get hpa. After a minute TARGETS shows a percentage, not <unknown>.

  8. 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 no replicas: line (helm get manifest nw -n northwind | grep -A30 'name: nw-osos-core-rest$' | grep replicas).

  9. In inventory.md, write what you would change for production, using your kubectl top figures.

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 seeWhat to do
kubectl top says metrics are not availableWait a minute; check the metrics server pod is ready and has the --kubelet-insecure-tls argument.
Step 6 fails on a quoted numberWrite 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 changeThe lab limit is too low for your use; raise limits.memory to 2560Mi and the heap to 1920.
The upgrade waits a long timeChanging 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”
PracticeChoose one answer.

An operator adds core.data.autoscaling.enabled: true with a CPU target, and the upgrade fails before anything changes in the cluster. Why?

  1. Explanation for A

    ✓ Correct

    Correct: enabling a combined pod’s autoscaler is always a two-value change. See Autoscaling a combined pod.

  2. Explanation for B

    ✗ Incorrect

    Not this one: core-data can be autoscaled once its requests are set. See Autoscaling a combined pod.

  3. Explanation for C

    ✗ Incorrect

    Not this one: the chart cannot see your metrics server; it checks the values. See Autoscaling a combined pod.

Check your answer

The correct answer is A. Open the explanation under each option to see why.

PracticeChoose one answer.

core-rest has a 2 GiB memory limit and --max-old-space-size=3072. What happens under load?

  1. Explanation for A

    ✗ Incorrect

    Not this one: the container cannot use more than its limit. See Autoscaling a combined pod.

  2. Explanation for B

    ✓ Correct

    Correct: keep the heap at about 75 % of the memory limit. See Autoscaling a combined pod.

  3. Explanation for C

    ✗ Incorrect

    Not this one: the heap limit comes from the option you set, not from the container. See Autoscaling a combined pod.

Check your answer

The correct answer is B. Open the explanation under each option to see why.

PracticeChoose one answer.

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?

  1. Explanation for A

    ✗ Incorrect

    Not this one: the autoscaler reads an external metric served by Kubernetes, not RabbitMQ directly. See Autoscaling the standalone services.

  2. Explanation for B

    ✓ Correct

    Correct: add an adapter rule over a RabbitMQ exporter, or put a CPU target back while you do. See Autoscaling the standalone services.

  3. Explanation for C

    ✗ Incorrect

    Not this one: the target cannot matter while the metric itself is unknown. See Autoscaling the standalone services.

Check your answer

The correct answer is B. Open the explanation under each option to see why.

PracticeChoose one answer.

Scheduled reminders sometimes run late. A colleague proposes four scheduler replicas. What do you say?

  1. Explanation for A

    ✗ Incorrect

    Not this one: the scheduler locks each job while it runs, so throughput does not grow with replicas. See Find the bottleneck first.

  2. Explanation for B

    ✓ Correct

    Correct: extra scheduler replicas add availability, not throughput. See Find the bottleneck first.

  3. Explanation for C

    ✗ Incorrect

    Not this one: autoscaling adds the same replicas, with the same lack of effect. See Find the bottleneck first.

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.