I manage to run Ollama as a k8s STS. I am using it for Python Langchain LLM/RAG application. However the following Dockerfile ENTRYPOINT script which tries to pull a list of images exported as MODELS ENV from k8s STS manifest runs into problem. Dockerfile has the following ENTRYPOINT and CMD:
ENTRYPOINT ["/usr/local/bin/run.sh"]
CMD ["bash"]
run.sh:
#!/bin/bash
set -x
ollama serve&
sleep 10
models="${MODELS//,/ }"
for i in "${models[@]}"; do \
echo model: $i \
ollama pull $i \
done
k8s logs:
+ models=llama3.2
/usr/local/bin/run.sh: line 10: syntax error: unexpected end of file
David Maze's solution:
lifecycle:
postStart:
exec:
command:
- bash
- -c
- |
for i in $(seq 10); do
ollama ps && break
sleep 1
done
for model in ${MODELS//,/ }; do
ollama pull "$model"
done
ollama-0 1/2 CrashLoopBackOff 4 (3s ago) 115s
ollama-1 1/2 CrashLoopBackOff 4 (1s ago) 115s
Warning FailedPostStartHook 106s (x3 over 2m14s) kubelet PostStartHook failed
$ k logs -fp ollama-0
Defaulted container "ollama" out of: ollama, fluentd
Error: unknown command "ollama" for "ollama"
Update Dockerfile:
ENTRYPOINT ["/bin/ollama"]
#CMD ["bash"]
CMD ["ollama", "serve"]
I need the customized Dockerfile so that I could install Nvidia Container Toolkit.