titan-iac/services/ai-llm/deployment.yaml

134 lines
4.0 KiB
YAML
Raw Permalink Normal View History

# services/ai-llm/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: ollama
namespace: ai
spec:
2026-06-29 14:28:21 -03:00
replicas: 1
revisionHistoryLimit: 2
strategy:
2026-01-01 14:48:54 -03:00
type: RollingUpdate
rollingUpdate:
maxSurge: 0
maxUnavailable: 1
selector:
matchLabels:
app: ollama
template:
metadata:
labels:
app: ollama
annotations:
ai.bstein.dev/model: qwen2.5-coder:1.5b-instruct-q4_0,qwen2.5:14b-instruct-q4_0
ai.bstein.dev/gpu: GPU pool (titan-20/21)
ai.bstein.dev/restartedAt: "2026-01-26T12:00:00Z"
spec:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- titan-20
- titan-21
runtimeClassName: nvidia
volumes:
- name: models
# Accelerator nodes are not Longhorn attach targets; keep the model cache pod-local.
emptyDir: {}
initContainers:
- name: warm-model
image: ollama/ollama@sha256:2c9595c555fd70a28363489ac03bd5bf9e7c5bdf2890373c3a830ffd7252ce6d
env:
- name: OLLAMA_HOST
value: 0.0.0.0
- name: NVIDIA_VISIBLE_DEVICES
value: all
- name: NVIDIA_DRIVER_CAPABILITIES
value: compute,utility
- name: OLLAMA_MODELS
value: /root/.ollama
- name: OLLAMA_MODEL
value: qwen2.5:14b-instruct-q4_0
2026-06-29 15:06:44 -03:00
- name: OLLAMA_FAST_MODEL
value: qwen2.5-coder:1.5b-instruct-q4_0
command:
- /bin/sh
- -c
- |
set -e
ollama serve >/tmp/ollama.log 2>&1 &
sleep 6
2026-06-29 15:06:44 -03:00
for model in "${OLLAMA_FAST_MODEL}" "${OLLAMA_MODEL}"; do
ollama pull "${model}"
done
pkill ollama || true
volumeMounts:
- name: models
mountPath: /root/.ollama
resources:
requests:
cpu: 500m
memory: 2Gi
nvidia.com/gpu.shared: 1
limits:
2026-06-29 14:33:32 -03:00
cpu: "2"
memory: 4Gi
nvidia.com/gpu.shared: 1
containers:
- name: ollama
image: ollama/ollama@sha256:2c9595c555fd70a28363489ac03bd5bf9e7c5bdf2890373c3a830ffd7252ce6d
imagePullPolicy: IfNotPresent
ports:
- name: http
containerPort: 11434
env:
- name: OLLAMA_HOST
value: 0.0.0.0
2026-06-29 15:33:50 -03:00
- name: OLLAMA_FAST_MODEL
value: qwen2.5-coder:1.5b-instruct-q4_0
- name: OLLAMA_KEEP_ALIVE
value: 6h
- name: OLLAMA_MODELS
value: /root/.ollama
- name: NVIDIA_VISIBLE_DEVICES
value: all
- name: NVIDIA_DRIVER_CAPABILITIES
value: compute,utility
2026-06-29 15:33:50 -03:00
command:
- /bin/sh
- -c
- |
set -e
ollama serve &
pid="$!"
trap 'kill -TERM "$pid"; wait "$pid"' TERM INT
sleep 6
timeout 180s ollama run "${OLLAMA_FAST_MODEL}" "reply with just pong" >/tmp/ollama-fast-warm.log 2>&1
touch /tmp/ollama-fast-ready
wait "$pid"
volumeMounts:
- name: models
mountPath: /root/.ollama
readinessProbe:
2026-06-29 15:33:50 -03:00
exec:
command:
- /bin/sh
- -c
- test -f /tmp/ollama-fast-ready && ollama list >/dev/null 2>&1
initialDelaySeconds: 15
periodSeconds: 10
timeoutSeconds: 5
resources:
requests:
cpu: "4"
2026-06-29 14:43:20 -03:00
memory: 10Gi
nvidia.com/gpu.shared: 1
limits:
cpu: "8"
2026-06-29 14:43:20 -03:00
memory: 14Gi
nvidia.com/gpu.shared: 1