Skip to content

Fix KServe minReplicas=0 Support for Scale-to-Zero#1427

Open
Leoyzen wants to merge 1 commit intokubeflow:masterfrom
Leoyzen:fix/min-replicas-scale-to-zero
Open

Fix KServe minReplicas=0 Support for Scale-to-Zero#1427
Leoyzen wants to merge 1 commit intokubeflow:masterfrom
Leoyzen:fix/min-replicas-scale-to-zero

Conversation

@Leoyzen
Copy link
Copy Markdown
Contributor

@Leoyzen Leoyzen commented Mar 3, 2026

Problem

This PR addresses two critical issues with the minReplicas configuration in KServe:

Issue 1: Helm Template Condition Fails for minReplicas=0

The Helm template used {{- if .Values.minReplicas }} to conditionally render the minReplicas field. In Helm, the value 0 is falsy, so when users set minReplicas: 0 to enable scale-to-zero, the configuration was silently ignored and not rendered in the generated manifest.

Issue 2: Update Command Resets minReplicas to 1

When updating an InferenceService with any field (not --min-replicas), the minReplicas value was always reset to 1. This occurred because:

  • The default value for --min-replicas flag was 1 in the update command
  • The update logic checked if args.MinReplicas >= 0, which was always true (default 1 >= 0)
  • This overwrote existing minReplicas settings, breaking scale-to-zero deployments

Solution

1. Fixed Helm Template Condition

Changed the condition from:

{{- if .Values.minReplicas }}

To:

{{- if ge (int .Values.minReplicas) 0 }}

This ensures that minReplicas=0 is correctly rendered since 0 >= 0 evaluates to true.

2. Fixed Update Command Default Value

Changed the default value of --min-replicas flag in update_serving_kserve.go from 1 to -1:

command.Flags().IntVar(&s.args.MinReplicas, "min-replicas", -1, "...")

Now:

  • When --min-replicas is not specified, args.MinReplicas = -1, condition >= 0 is false, no update occurs
  • When --min-replicas 0 is explicitly set, args.MinReplicas = 0, condition >= 0 is true, updates to 0
  • When --min-replicas <N> (N>0) is explicitly set, updates to the specified value

Files Changed

  • charts/kserve/templates/inferenceservice.yaml - Fixed Helm template condition
  • charts/kserve/values.yaml - Added default values for minReplicas: 0 and maxReplicas: 10
  • pkg/argsbuilder/update_serving_kserve.go - Changed default --min-replicas to -1

Behavior

Create New InferenceService:

  • Default minReplicas remains 1 (no breaking change)
  • Users can explicitly set --min-replicas 0 for scale-to-zero

Update InferenceService:

  • Updating other fields no longer resets minReplicas
  • Users can explicitly set --min-replicas 0 to enable scale-to-zero
  • Users can explicitly set --min-replicas <N> to change the value

Testing Recommendations

  1. Deploy a new InferenceService with --min-replicas 0 and verify scale-to-zero works
  2. Update an existing InferenceService (changing non-minReplicas fields) and verify minReplicas is preserved
  3. Update an existing InferenceService with --min-replicas 0 and verify it enables scale-to-zero
  4. Verify existing deployments without explicit minReplicas continue to work as before

Related

This fix enables true scale-to-zero functionality for KServe inference services, which is essential for cost optimization in development/test environments and low-traffic production workloads.

@google-oss-prow
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign gujingit for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

…t on update

This commit fixes two issues with minReplicas configuration in KServe:

1. Helm template condition fix:
   - Changed template condition from 'if .Values.minReplicas' to
     'if ge (int .Values.minReplicas) 0'
   - This ensures minReplicas=0 is correctly rendered instead of being
     ignored (since 0 is falsy in Helm)

2. Update command default value fix:
   - Changed default value of --min-replicas flag from 1 to -1 in
     update_serving_kserve.go
   - Update logic only applies when args.MinReplicas >= 0
   - Now updating other fields won't reset minReplicas to 1

Files changed:
- charts/kserve/templates/inferenceservice.yaml
- charts/kserve/values.yaml
- pkg/argsbuilder/update_serving_kserve.go

Fixes scale-to-zero (minReplicas=0) functionality for KServe inference
services.
@Leoyzen Leoyzen force-pushed the fix/min-replicas-scale-to-zero branch from 13d45a6 to 90b87b6 Compare March 3, 2026 01:58
@google-oss-prow google-oss-prow bot added size/XS and removed size/S labels Mar 3, 2026
@ChenYi015
Copy link
Copy Markdown
Member

@Leoyzen Thanks for reporting and fixing the issue! Could you sign off your commits to pass the DCO check? See Contributing | Kubeflow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants