Implementation:Kserve Kserve TrainedModel CRD Spec
| Knowledge Sources | |
|---|---|
| Domains | MLOps, Model_Management, Kubernetes |
| Last Updated | 2026-02-13 00:00 GMT |
Overview
Concrete Go type definitions for the TrainedModel CRD that registers individual model artifacts with a shared InferenceService.
Description
The TrainedModel CRD is defined in pkg/apis/serving/v1alpha1/trained_model.go. The spec contains an InferenceService reference (parent ISVC name), a Model field with StorageURI, Framework, and Memory. The webhook validates naming, storage URI scheme, and memory constraints.
Usage
Create TrainedModel resources pointing to a running MMS InferenceService. Each TrainedModel gets its own prediction endpoint under the shared ISVC host.
Code Reference
Source Location
- Repository: kserve
- File: pkg/apis/serving/v1alpha1/trained_model.go, Lines 33-81
Signature
// TrainedModel registers a model with a shared InferenceService
type TrainedModel struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec TrainedModelSpec `json:"spec,omitempty"`
Status TrainedModelStatus `json:"status,omitempty"`
}
// TrainedModelSpec defines the model to register
type TrainedModelSpec struct {
InferenceService string `json:"inferenceService"`
Model ModelSpec `json:"model"`
}
// ModelSpec defines the model artifact
type ModelSpec struct {
StorageURI string `json:"storageUri"`
Framework string `json:"framework"`
Memory resource.Quantity `json:"memory"`
}
// TotalRequestedMemory sums memory of all TrainedModels for a parent ISVC
func TotalRequestedMemory(models []TrainedModel) resource.Quantity
Import
import servingv1alpha1 "github.com/kserve/kserve/pkg/apis/serving/v1alpha1"
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| spec.inferenceService | string | Yes | Name of parent MMS InferenceService |
| spec.model.storageUri | string | Yes | Model artifact URI (s3://, gs://, https://) |
| spec.model.framework | string | Yes | ML framework (sklearn, xgboost, pytorch, etc.) |
| spec.model.memory | resource.Quantity | Yes | Estimated model memory usage |
Outputs
| Name | Type | Description |
|---|---|---|
| status.conditions | []Condition | InferenceServiceReady, IsMMSPredictor, MemoryResourceAvailable |
| status.url | URL | Per-model prediction endpoint URL |
| ConfigMap entry | JSON | Model spec written to modelconfig-<isvc>-0 |
Usage Examples
Register Two Models
apiVersion: serving.kserve.io/v1alpha1
kind: TrainedModel
metadata:
name: model1-sklearn
spec:
inferenceService: sklearn-iris-example
model:
storageUri: "gs://kfserving-examples/models/sklearn/1.0/model"
framework: sklearn
memory: 256Mi
---
apiVersion: serving.kserve.io/v1alpha1
kind: TrainedModel
metadata:
name: model2-sklearn
spec:
inferenceService: sklearn-iris-example
model:
storageUri: "gs://kfserving-examples/models/sklearn/1.0/model-2"
framework: sklearn
memory: 256Mi
kubectl apply -f trainedmodels.yaml
kubectl get trainedmodels
# NAME URL READY
# model1-sklearn True
# model2-sklearn True