Triton on OpenShift
Deploy NVIDIA Triton Inference Server on OpenShift and serve a custom ONNX or PyTorch model from a model repository.
Triton serves the models a NIM does not ship. You give it a model repository: a directory per model, a config.pbtxt, and the weight file. This lab deploys Triton on OpenShift and serves a tiny ONNX model, then shows the one-line change for a PyTorch model. The overview is the decision to be here at all.
Prerequisites
- OpenShift 4.x with the NVIDIA GPU Operator, so pods can request
nvidia.com/gpu - A project
modelsand permission to create a Deployment, a Service and a PersistentVolumeClaim ocandcurl
A GPU is required for the deployment below. The same manifest works without one if you remove the resource limit and set the model instance group to KIND_CPU. Do that only to see the API. The later labs assume a GPU.
A model repository
Triton looks for /models/<name>/config.pbtxt and /models/<name>/<version>/model.onnx. Build a softmax over four logits so the request is small enough to type.
import torch
class Softmax(torch.nn.Module):
def forward(self, x):
return torch.softmax(x, dim=-1)
torch.onnx.export(
Softmax(), torch.randn(1, 4), "model.onnx",
input_names=["input"], output_names=["probs"],
dynamo=False, opset_version=17,
)
name: "softmax"
platform: "onnxruntime_onnx"
max_batch_size: 8
input [
{ name: "input" data_type: TYPE_FP32 dims: [ 4 ] }
]
output [
{ name: "probs" data_type: TYPE_FP32 dims: [ 4 ] }
]
instance_group [ { kind: KIND_GPU count: 1 } ]
max_batch_size: 8 means the config's dims omit the batch, and the client sends it. Put config.pbtxt in softmax/ and model.onnx in softmax/1/. For a TorchScript model, set platform: "pytorch_libtorch" and store model.pt instead of model.onnx. The rest of the repository layout stays the same.
Deploy Triton
apiVersion: apps/v1
kind: Deployment
metadata:
name: triton
namespace: models
spec:
replicas: 1
selector:
matchLabels: { app: triton }
template:
metadata:
labels: { app: triton }
spec:
containers:
- name: triton
image: nvcr.io/nvidia/tritonserver:25.10-py3
args: ["tritonserver", "--model-repository=/models"]
ports:
- { name: http, containerPort: 8000 }
- { name: grpc, containerPort: 8001 }
- { name: metrics, containerPort: 8002 }
resources:
limits:
nvidia.com/gpu: "1"
readinessProbe:
httpGet: { path: /v2/health/ready, port: http }
volumeMounts:
- { name: models, mountPath: /models }
volumes:
- name: models
persistentVolumeClaim:
claimName: model-repo
oc apply -f pvc.yaml -f deployment.yaml
oc cp softmax models/$(oc get pod -n models -l app=triton -o name | head -1 | cut -d/ -f2):/models/softmax
oc expose deployment/triton -n models --port=8000
oc get route triton -n models
/v2/health/ready stays failed until every model in the repository loads. A bad config.pbtxt shows up in the pod log as a model that failed to load, and the other models can still be ready if you set --exit-on-error=false. The default is to refuse readiness when any model fails, which is what you want in a lab with one model.
Call it
curl -s -X POST "$(oc get route triton -n models -o jsonpath='https://{.spec.host}')/v2/models/softmax/infer" \
-H 'Content-Type: application/json' \
-d '{"inputs":[{"name":"input","shape":[1,4],"datatype":"FP32","data":[1,2,3,4]}]}'
The response carries probs with four numbers that sum to about one. Reload after you change the model by replacing the files under softmax/1/ and posting to /v2/repository/models/softmax/load, or by restarting the pod. Prefer a new version directory (softmax/2) so you can point clients back at version 1.
Metrics are on port 8002, path /metrics. Scrape that with the same Prometheus the Kafka monitoring lab uses, and you can see queue time separately from compute time. A slow client is often queue time. A slow model is compute time. The config's instance_group count is what you raise when compute is fine and requests are waiting.
What's next
- Chain a Python pre-process and post-process around this model in model ensembles.
- Serve an LLM, rather than this toy ONNX, with TensorRT-LLM or a NIM, as the overview distinguishes.
- Call the same style of HTTP endpoint from a stream processor in Kafka for AI.