Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:Kserve Kserve Knative Traffic Reconciler

From Leeroopedia
Knowledge Sources
Domains MLOps, Deployment_Strategy, Traffic_Management
Last Updated 2026-02-13 00:00 GMT

Overview

Concrete Go reconciler that translates canaryTrafficPercent values into Knative Service traffic targets for progressive rollout.

Description

The Knative service reconciler's createKnativeService() function constructs traffic targets from the InferenceService's canaryTrafficPercent field. It creates two targets: one for the latest revision (canary) with the specified percentage, and one for the previous revision (stable) with the remainder. When tag routing is enabled, it adds latest and prev tags for deterministic routing.

Usage

This reconciler is invoked automatically during InferenceService reconciliation when using Serverless deployment mode (the default). Each update to canaryTrafficPercent triggers reconciliation with new traffic targets.

Code Reference

Source Location

  • Repository: kserve
  • File: pkg/controller/v1beta1/inferenceservice/reconcilers/knative/ksvc_reconciler.go, Lines 132-164 (traffic construction)
  • File: docs/samples/v1beta1/tensorflow/canary.yaml, Lines 1-9 (example usage)

Signature

// createKnativeService builds a Knative Service with traffic targets
func createKnativeService(
    componentMeta metav1.ObjectMeta,
    componentExt *v1beta1.ComponentExtensionSpec,
    podSpec *corev1.PodSpec,
) *knservingv1.Service

// Traffic target construction (simplified)
// When canaryTrafficPercent is set:
// targets = [
//   {RevisionName: previousRevision, Percent: 100 - canaryPercent, Tag: "prev"},
//   {LatestRevision: true, Percent: canaryPercent, Tag: "latest"},
// ]

Import

import "github.com/kserve/kserve/pkg/controller/v1beta1/inferenceservice/reconcilers/knative"

I/O Contract

Inputs

Name Type Required Description
canaryTrafficPercent *int64 No Traffic percentage for canary revision (0-100)
componentMeta metav1.ObjectMeta Yes Component metadata for naming
podSpec *corev1.PodSpec Yes Pod specification for the serving container

Outputs

Name Type Description
Knative Service knservingv1.Service Service with traffic targets reflecting canary split
Traffic targets []TrafficTarget Latest (canary) and previous (stable) targets with percentages

Usage Examples

Update Traffic to 20%

apiVersion: serving.kserve.io/v1beta1
kind: InferenceService
metadata:
  name: my-model
spec:
  predictor:
    canaryTrafficPercent: 20
    tensorflow:
      storageUri: "gs://kfserving-examples/models/tensorflow/flowers-2"
# Apply and verify traffic split
kubectl apply -f canary-20.yaml
kubectl get ksvc my-model-predictor-default -o jsonpath='{.spec.traffic}'
# Output: [{"percent":80,"revisionName":"...00001","tag":"prev"},
#          {"latestRevision":true,"percent":20,"tag":"latest"}]

Related Pages

Implements Principle

Requires Environment

Uses Heuristic

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment