Yet another operator for running large language models on Kubernetes with ease. π
Powered by Ollama! π«
While Ollama is a powerful tool for running large language models locally, and the user experience of CLI is just the same as using Docker CLI, it's not possible yet to replicate the same user experience on Kubernetes, especially when it comes to running multiple models on the same cluster with loads of resources and configurations.
That's where the Ollama Operator kicks in:
- Install the operator on your Kubernetes cluster
- Apply the needed CRDs
- Create your models
- Wait for the models to be fetched and loaded, that's it!
Thanks to the great works of lama.cpp, no more worries about Python environment, CUDA drivers.
The journey to large language models, AIGC, localized agents, π¦π Langchain and more is just a few steps away!
- β Abilities to run multiple models on the same cluster.
- β Compatible with all Ollama models, APIs, and CLI.
- β Able to run on general Kubernetes clusters, K3s clusters (Respberry Pi, TrueNAS SCALE, etc.), kind, minikube, etc. You name it!
- β Easy to install, uninstall, and upgrade.
- β Pull image once, share across the entire node (just like normal images).
- β Easy to expose with existing Kubernetes services, ingress, etc.
- β Doesn't require any additional dependencies, just Kubernetes
kubectl apply \
--server-side=true \
-f https://raw.githubusercontent.com/nekomeowww/ollama-operator/v0.10.1/dist/install.yaml
kubectl wait \
-n ollama-operator-system \
--for=jsonpath='{.status.readyReplicas}'=1 \
deployment/ollama-operator-controller-manager
Note
You can also use the kollama
CLI natively shipped by Ollama Operator, and will be easier to interact with the operator.
Install kollama
CLI:
go install github.com/nekomeowww/ollama-operator/cmd/kollama@latest
Deploy a model can be done with the following command:
kollama deploy phi --expose --node-port 30001
More information can be found at CLI
Important
Working with kind
?
The default provisioned StorageClass
in kind
is standard
, and will only work with ReadWriteOnce
access mode, therefore if you would need to run the operator with kind
, you should specify persistentVolume
with accessMode: ReadWriteOnce
in the Model
CRD:
apiVersion: ollama.ayaka.io/v1
kind: Model
metadata:
name: phi
spec:
image: phi
persistentVolume:
accessMode: ReadWriteOnce
Let's create a Model
CR for the model phi
:
apiVersion: ollama.ayaka.io/v1
kind: Model
metadata:
name: phi
spec:
image: phi
Apply the Model
CR to your Kubernetes cluster:
kubectl apply -f ollama-model-phi.yaml
Wait for the model to be ready:
kubectl wait --for=jsonpath='{.status.readyReplicas}'=1 deployment/ollama-model-phi
- Ready! Now let's forward the ports to access the model:
kubectl port-forward svc/ollama-model-phi ollama
- Interact with the model:
ollama run phi
apiVersion: ollama.ayaka.io/v1
kind: Model
metadata:
name: phi
spec:
# Scale the model to 2 replicas
replicas: 2
# Use the model image `phi`
image: phi
imagePullPolicy: IfNotPresent
storageClassName: local-path
# If you have your own PersistentVolumeClaim created
persistentVolumeClaim: your-pvc
# If you need to specify the access mode for the PersistentVolume
persistentVolume:
accessMode: ReadWriteOnce
Unlock the abilities to run the following models with the Ollama Operator over Kubernetes:
Tip
By the power of Modelfile
backed by Ollama, you can create and bundle any of your own model. As long as it's a GGUF formatted model.
Full list of available images can be found at Ollama Library.
Warning
You should have at least 8 GB of RAM available on your node to run the 7B models, 16 GB to run the 13B models, and 32 GB to run the 33B models.
Warning
The actual size of downloaded large language models are huge by comparing to the size of general container images.
- Fast and stable network connection is recommended to download the models.
- Efficient storage is required to store the models if you want to run models larger than 13B.
There are two major components that the Ollama Operator will create for:
- Model Inferencing Server: The model inferencing server is a gRPC server that runs the model and serves the model's API. It is created as a
Deployment
in the Kubernetes cluster. - Model Image Storage: The model image storage is a
PersistentVolume
that stores the model image. It is created as aStatefulSet
along with aPersistentVolumeClaim
in the Kubernetes cluster.
Note
The image that created by Modelfile
of Ollama is a valid OCI format image, however, due to the incompatible contentType
value, and the overall structure of the Modelfile
image to the general container image, it's not possible to run the model directly with the general container runtime. Therefore a standalone service/deployment of Model Image Storage is required to be persisted on the Kubernetes cluster in order to hold and cache the previously downloaded model image.
The detailed resources it creates, and the relationships between them are shown in the following diagram:
- Refer to the CONTRIBUTING.md for more information.
- More information can be found via the Kubebuilder Documentation
Gratefully thanks to the following projects and their authors, contributors:
It is because of their hard work and contributions that this program exists.