Skip to content
GPU infrastructure on Kubernetes · Chapter 16 of 19 Day 14: A Model on the Cluster

Day 14: A Model on the Cluster

Goal: Run a small language model as a service on the cluster: Deployment, Service, resources, measuring response speed. Then send the same application with a GPU request to the GPU node and take an honest look at what a simulated GPU means for a model, and what would be different on real hardware · Duration: approx. 75 min · Prerequisite: Day 8

Briefing

  • So far, only sleep and nvidia-smi have run on the GPUs. Today something runs that platform teams actually operate: a language model behind an HTTP interface.
  • Ollama packs model download, runtime (llama.cpp) and API into one container. The model qwen2.5:0.5b has half a billion parameters and is 397 MB in size, small enough for a CPU node with a few GB of memory.
  • Honesty rule: Mokka simulates NVML, not CUDA. A program that really wants to compute on the GPU finds no usable GPU and falls back to the CPU if it can. That is exactly what Drill 5 shows. All measurements today are CPU values.
  Pod frage (curl) ──▶ Service modell:11434 ──▶ Ollama (gpu-worker, CPU) ──▶ qwen2.5:0.5b
  Pod frage (curl) ──▶ Service modell-gpu   ──▶ Ollama (gpu-worker2, 1 Mokka-GPU) ──▶ computes on the CPU anyway

Drill 1: The Model as a Deployment

A Deployment on the CPU node, with resources that fit the model and a readiness probe on the API. The models live in /root/.ollama, here in an emptyDir for now:

mkdir -p ~/gpu/tag14 && cd ~/gpu/tag14
kubectl create ns tag14
cat > ollama.yaml <<'EOF'
apiVersion: apps/v1
kind: Deployment
metadata:
  name: modell
  namespace: tag14
spec:
  replicas: 1
  selector:
    matchLabels: {app: modell}
  template:
    metadata:
      labels: {app: modell}
    spec:
      nodeSelector:
        kubernetes.io/hostname: gpu-worker
      containers:
      - name: ollama
        image: ollama/ollama:0.40.17
        ports:
        - containerPort: 11434
        resources:
          requests:
            cpu: "2"
            memory: 2Gi
          limits:
            memory: 3Gi
        readinessProbe:
          httpGet: {path: /, port: 11434}
          periodSeconds: 5
        volumeMounts:
        - name: modelle
          mountPath: /root/.ollama
      volumes:
      - name: modelle
        emptyDir: {}
---
apiVersion: v1
kind: Service
metadata:
  name: modell
  namespace: tag14
spec:
  selector: {app: modell}
  ports:
  - port: 11434
EOF
kubectl apply -f ollama.yaml
time kubectl -n tag14 rollout status deploy/modell --timeout=600s

Expected (abridged):

namespace/tag14 created
deployment.apps/modell created
service/modell created
deployment "modell" successfully rolled out

real    6m52.217s

Almost seven minutes, nearly all of it for the image: Ollama ships the libraries for CUDA, ROCm and Vulkan, 3.4 GB in total. AI images are large, and the first start on a node is correspondingly slow. If you add nodes automatically, preload such images.

Save your progress? Sign up for free

Drill 2: Load the Model and Ask It

kubectl -n tag14 exec deploy/modell -- ollama --version
time kubectl -n tag14 exec deploy/modell -- ollama pull qwen2.5:0.5b >/dev/null
kubectl -n tag14 exec deploy/modell -- ollama list
kubectl -n tag14 logs deploy/modell 2>&1 | grep 'inference compute' | cut -c1-200

Expected (abridged):

ollama version is 0.40.17

real    0m36.877s
NAME            ID              SIZE      MODIFIED
qwen2.5:0.5b    a8b0c5157701    397 MB    1 second ago
time=2026-11-24T06:36:41.895Z level=INFO source=types.go:50 msg="inference compute" id=cpu library=cpu compute="" name=cpu description=cpu libdirs=ollama driver="" pci_id="" type="" total="3.0 GiB" available="2.6 GiB"

inference compute … library=cpu: Ollama computes on the CPU and sees 3 GiB of memory, the container’s limit. A client Pod with curl asks the same question twice. Along with the answer, the API returns the measurements as well:

kubectl -n tag14 run frage --image=curlimages/curl:8.17.0 --restart=Never --command -- sleep 3600
kubectl -n tag14 wait --for=condition=Ready pod/frage --timeout=120s
for i in 1 2; do kubectl -n tag14 exec frage -- curl -s http://modell:11434/api/generate -d '{"model":"qwen2.5:0.5b","prompt":"Erkläre in zwei Sätzen, was eine GPU ist.","stream":false,"options":{"seed":1,"temperature":0}}' > antwort.json; jq -r '"load \(.load_duration/1e9|.*100|floor/100) s, \(.eval_count) Token in \(.eval_duration/1e9|.*100|floor/100) s = \(.eval_count/(.eval_duration/1e9)|floor) Token/s"' antwort.json; done
jq -r .response antwort.json | cut -c1-160

Expected:

pod/frage created
pod/frage condition met
load 4.58 s, 148 Token in 7.72 s = 19 Token/s
load 0 s, 178 Token in 8.3 s = 21 Token/s
Eine GPU (Gefahrsmaschinen) ist ein Computerteil, das speziell für die Berechnung von mathematischen und informellen Aufgaben verwendet wird. Sie ist ein Teil von
  • Loading: The first request loads the model into memory (4.6 s); the second finds it already there. Ollama unloads a model again after five minutes without a request; then the next user pays the load time.
  • Speed: around 20 tokens per second on two CPU cores. A token is roughly a word piece. That is enough to read along, but not for many concurrent users.
  • Quality: “Gefahrsmaschinen” (a made-up word, roughly “danger machines”) and a repetition loop. A model with half a billion parameters is a test object, not an assistant. From about 7 billion parameters it becomes usable, and then it needs memory that a CPU node does not have and compute power that only GPUs deliver.

Save your progress? Sign up for free

Drill 3: Not Enough Memory

What happens when the memory limit does not fit the model? First the Deployment switches to Recreate so that two Pods never run at the same time (the Challenge shows why), then the limit is lowered to 400 Mi:

kubectl -n tag14 patch deploy modell -p '{"spec":{"strategy":{"type":"Recreate","rollingUpdate":null}}}'
kubectl -n tag14 set resources deploy/modell --limits=memory=400Mi --requests=memory=300Mi,cpu=2
kubectl -n tag14 rollout status deploy/modell --timeout=180s | tail -1
kubectl -n tag14 exec deploy/modell -- ollama pull qwen2.5:0.5b >/dev/null
kubectl -n tag14 exec frage -- curl -s -m 90 http://modell:11434/api/generate -d '{"model":"qwen2.5:0.5b","prompt":"Hallo","stream":false}'; echo "curl: $?"
sleep 3
P=$(kubectl -n tag14 get pod -l app=modell -o name)
kubectl -n tag14 get $P -o jsonpath='{.status.containerStatuses[0].restartCount} {.status.containerStatuses[0].lastState.terminated.reason} {.status.containerStatuses[0].lastState.terminated.exitCode}{"\n"}'

Expected:

deployment.apps/modell patched
deployment.apps/modell resource requirements updated
deployment "modell" successfully rolled out
command terminated with exit code 52
curl: 52
1 OOMKilled 137

The server starts with 400 Mi without problems; it needs little when idle. Only when loading the model does it exceed the limit, and the kernel kills the container (OOMKilled, exit code 137). curl gets an empty reply (error 52). The VM’s kernel log has more detail:

sudo dmesg | grep -i 'killed process' | tail -1 | cut -c1-160

Expected:

[439164.423560] Memory cgroup out of memory: Killed process 1323163 (ollama) total-vm:3013296kB, anon-rss:117252kB, file-rss:132736kB, shmem-rss:0kB, UID:0 pgtables:1108kB oom_score_adj:963

The rule of thumb for model memory: model file size plus context memory plus runtime, so for the 397 MB model a good 1 GB. On real GPUs, the same calculation applies to GPU memory: a model with 7 billion parameters in 16 bits needs 14 GB plus context, so it fits on an A100 with 40 GB but not on a T4 with 16 GB. Restore the limits:

kubectl -n tag14 set resources deploy/modell --limits=memory=3Gi --requests=memory=2Gi,cpu=2
kubectl -n tag14 rollout status deploy/modell --timeout=180s | tail -1

Expected:

deployment.apps/modell resource requirements updated
deployment "modell" successfully rolled out

Save your progress? Sign up for free

Drill 4: The Model Is Gone

kubectl -n tag14 exec deploy/modell -- ollama list

Expected:

NAME    ID    SIZE    MODIFIED

Empty. Every change to the Deployment creates a new Pod, and with it a new emptyDir. At 397 MB that is a nuisance; at 40 GB it is an outage, because every new Pod first downloads for minutes. In production, models live on a PersistentVolume, in an image volume (an OCI image that Kubernetes mounts as a volume) or in a cache on the node, and an init container loads them before the readiness probe turns green. Otherwise a Pod that reports “ready” without having the model yet delivers nothing but errors for the first few minutes.

Save your progress? Sign up for free

Drill 5: The Same with a GPU

A copy of the Deployment, but with one GPU and the toleration for the GPU node instead of the nodeSelector. A small piece of Python generates it from ollama.yaml so the two differ only in these points:

cd ~/gpu/tag14
python3 - <<'EOF'
s = open("ollama.yaml").read().split("---")[0]
s = s.replace("name: modell\n", "name: modell-gpu\n", 1).replace("app: modell}", "app: modell-gpu}")
s = s.replace("      nodeSelector:\n        kubernetes.io/hostname: gpu-worker\n",
              "      tolerations:\n      - key: nvidia.com/gpu\n        operator: Exists\n        effect: NoSchedule\n")
s = s.replace("          limits:\n            memory: 3Gi\n", "          limits:\n            memory: 3Gi\n            nvidia.com/gpu: 1\n")
open("ollama-gpu.yaml", "w").write(s)
EOF
grep -nE 'name: modell-gpu|nvidia.com/gpu|tolerations' ollama-gpu.yaml
kubectl apply -f ollama-gpu.yaml
kubectl -n tag14 expose deploy/modell-gpu --port 11434
kubectl -n tag14 rollout status deploy/modell-gpu --timeout=900s | tail -1
kubectl -n tag14 exec deploy/modell-gpu -- sh -c 'nvidia-smi -L; ls /dev/nvidia*'
kubectl -n tag14 logs deploy/modell-gpu 2>&1 | grep 'inference compute' | cut -c1-200

Expected (abridged):

4:  name: modell-gpu
14:      tolerations:
15:      - key: nvidia.com/gpu
29:            nvidia.com/gpu: 1
deployment.apps/modell-gpu created
service/modell-gpu exposed
deployment "modell-gpu" successfully rolled out
GPU 0: NVIDIA A100-SXM4-40GB (UUID: GPU-12345678-1234-1234-1234-123456780001)
/dev/nvidia-uvm
/dev/nvidia-uvm-tools
/dev/nvidia1
time=2026-11-24T06:49:10.468Z level=INFO source=types.go:50 msg="inference compute" id=cpu library=cpu compute="" name=cpu description=cpu libdirs=ollama driver="" pci_id="" type="" total="3.0 GiB" available="2.5 GiB"

The Kubernetes side did everything right: the Pod runs on gpu-worker2, got exactly one GPU via DRA, sees it in nvidia-smi and has the device file /dev/nvidia1. At startup, Ollama looks for GPUs, finds none on which it could run CUDA programs, and again reports library=cpu. The measurement confirms it:

kubectl -n tag14 exec deploy/modell-gpu -- ollama pull qwen2.5:0.5b >/dev/null
kubectl -n tag14 exec frage -- curl -s http://modell-gpu:11434/api/generate -d '{"model":"qwen2.5:0.5b","prompt":"Erkläre in zwei Sätzen, was eine GPU ist.","stream":false,"options":{"seed":1,"temperature":0}}' > antwort-gpu.json
jq -r '"load \(.load_duration/1e9|.*100|floor/100) s, \(.eval_count) Token in \(.eval_duration/1e9|.*100|floor/100) s = \(.eval_count/(.eval_duration/1e9)|floor) Token/s"' antwort-gpu.json

Expected:

load 3.48 s, 148 Token in 7.7 s = 19 Token/s

19 tokens per second, as on the CPU node. A simulated GPU cannot do more. On real hardware, the inference compute line would instead show library=cuda with the model and free GPU memory, the entire model would sit in GPU memory, and an A100 produces several hundred tokens per second with such a small model. What you practiced on the Kubernetes side today is exactly the same there: request a GPU, land on the right node, size memory correctly, keep the model available.

Save your progress? Sign up for free

Exercise: Speed Drills

  1. Which node is modell running on? Target time: 20 s
  2. Which update strategy and which resources does modell have? Target time: 30 s
  3. Which claim belongs to modell-gpu? Target time: 20 s

Solution

kubectl -n tag14 get pod -l app=modell -o jsonpath='{.items[0].spec.nodeName}{"\n"}'
kubectl -n tag14 get deploy modell -o jsonpath='{.spec.strategy.type} {.spec.template.spec.containers[0].resources}{"\n"}'
kubectl -n tag14 get resourceclaim

Expected:

gpu-worker
Recreate {"limits":{"memory":"3Gi"},"requests":{"cpu":"2","memory":"2Gi"}}
NAME                                                   STATE                AGE
modell-gpu-7b48fd7888-m7shh-extended-resources-6t5gh   allocated,reserved   8m47s

Save your progress? Sign up for free

Challenge

A colleague changed only the memory limit on the original Deployment (still with the default strategy RollingUpdate). Since then there have been two Pods, one of them waiting:

NAME                      READY   STATUS    RESTARTS   AGE
modell-799dddb587-rksxw   0/1     Pending   0          2m8s
modell-bbdf5fc67-65p4q    1/1     Running   0          10m

Why does the new Pod wait even though the node has enough memory, and how do you prevent this permanently?

Hint: How many Pods exist at the same time during a rolling update, and what does each one request?

Solution

kubectl -n tag14 describe pod -l pod-template-hash=799dddb587 | grep FailedScheduling | sed 's/.*default-scheduler  //'
kubectl describe node gpu-worker | grep -A6 'Allocated resources' | tail -4

Expected:

0/3 nodes are available: 1 Insufficient cpu, 2 node(s) had untolerated taint(s). preemption: 0/3 nodes are available: 1 No preemption victims found for incoming pod, 2 Preemption is not helpful for scheduling.
  --------           --------      ------
  cpu                2615m (65%)   2 (50%)
  memory             2802Mi (35%)  5Gi (64%)

Not memory but CPU: a rolling update first starts the new Pod and then terminates the old one. For a moment, two Pods each request 2 CPUs; the node has 4, of which other Pods already take more than 600m. The new Pod does not fit, and the old one does not go away before the new one is ready: a deadlock. For GPU workloads this is the rule, not the exception, because a model Pod often occupies an entire GPU or an entire node.

Solutions: strategy: Recreate (Drill 3, a short interruption during the update, but never a double request) or rollingUpdate: {maxSurge: 0, maxUnavailable: 1} with several replicas that are replaced one at a time. For services without interruption, you need spare capacity in the cluster for exactly one additional Pod.

Save your progress? Sign up for free

Checkpoint

kubectl -n tag14 get deploy

Expected:

NAME         READY   UP-TO-DATE   AVAILABLE   AGE
modell       1/1     1            1           21m
modell-gpu   1/1     1            1           8m48s

Clean-up

kubectl delete ns tag14
kubectl get resourceclaim -A

Expected:

namespace "tag14" deleted
No resources found

The Ollama image stays cached on both nodes; a new start takes seconds instead of minutes.

Interview Note

  • How much memory does a model need? Size of the weights (parameters × bytes per parameter, 2 at 16 bits, around 0.5 with 4-bit quantization) plus context memory plus runtime. This applies to RAM on the CPU as well as to GPU memory on the GPU.
  • Why does a model Pod start so slowly? Large image, model download, loading into memory. Preload images, keep models available on volumes or caches, report readiness only after loading.
  • How can you tell whether an inference server uses the GPU? From the startup log (with Ollama, library=cuda instead of cpu), from used GPU memory in nvidia-smi and from utilization in the DCGM Exporter.

Enterprise Note

  • For production, you usually use vLLM or TGI (Text Generation Inference) instead of Ollama: they batch many concurrent requests on one GPU (continuous batching) and thereby achieve a multiple of the throughput. Ollama is meant for development and small internal services.
  • GPU workloads need their own update strategies and capacity reserves. An inference service with four replicas on four GPUs cannot be updated without interruption unless there is a fifth GPU.
  • A model in a Pod is only the beginning: in front of it belong authentication, quotas per team (Kueue helps again here for batch jobs; for services, a gateway with limits) and measurements of latency and token throughput. The course “LLMs on Kubernetes hands-on” continues down this path.

Contents

More