Skip to content

Ollama on Kubernetes: OOMKilled under load because of the prompt cache

AItested on Ubuntu 24.04, k3s v1.37.2+k3s1, Ollama 0.40.19

The language model runs and the first questions work – then single requests abort after less than a second and RESTARTS goes up. The model's log shows no error, because the process was killed from outside.

Symptom

kubectl -n rag describe pod -l app=llm
    State:          Running
      Started:      Wed, 02 Dec 2026 14:16:19 +0000
    Last State:     Terminated
      Reason:       OOMKilled
      Exit Code:    137
      Started:      Wed, 02 Dec 2026 14:10:45 +0000
      Finished:     Wed, 02 Dec 2026 14:16:18 +0000
    Ready:          True
    Restart Count:  1

Ten of twelve load questions succeeded, the eleventh and twelfth aborted.

Diagnosis

Ollama writes the prompt cache limit to the log when it loads the model.

kubectl -n rag logs deployment/llm | grep 'size limit'
srv    load_model: prompt cache is enabled, size limit: 8192 MiB

kubectl -n rag logs deployment/llm | grep 'cache state' | tail -1
srv        update:  - cache state: 5 prompts, 332.648 MiB (limits: 8192.000 MiB, 4096 tokens, 74889 est)

Causes

8 GiB vs 3 GiBCache limit and pod limit know nothing of each other

The prompt cache may grow to 8192 MiB, the pod's limit is 3 GiB. Ollama does not ask how much memory Kubernetes allows it.

About 66 MiB per promptThe cache grows with every new question

After 15 prompts there were about 1085 MiB in the cache and 2997 MiB in the pod – just below the limit.

Fix

Set the cache limit in the deployment. Ollama passes variables starting with LLAMA_ARG_ to its built-in llama.cpp server.
env:
  - name: OLLAMA_KEEP_ALIVE
    value: "-1"
  - name: LLAMA_ARG_CACHE_RAM
    value: "256"

kubectl -n rag logs deployment/llm | grep 'size limit'
srv    load_model: prompt cache is enabled, size limit: 256 MiB

kubectl -n rag top pod -l app=llm
NAME                   CPU(cores)   MEMORY(bytes)   
llm-579476976d-tfzfg   11752m       2198Mi

Don't: Look for the reason in the container log. OOMKilled only shows in kubectl describe pod under Last State.

▶
Break it yourself and find it – free
RAG infrastructure on Kubernetes hands-on, day 10: load and latency budget – load tests, memory and the language model's prompt cache.
Go to day 10 →

FAQ

Why does the Ollama log show no error?

The kernel kills the container with signal 9 (exit code 137 = 128 + 9). The process cannot write anything to the log.

Why does grep 'size limit' print nothing?

Ollama writes the line only when it loads the model – that is, on the first question after the start.

Related error patterns

More