Overview
ClusterAIScaleTemplate watches for Deployments, StatefulSets, and Argo Rollouts that match a label selector, and automatically creates corresponding AIScaleTargets with a predefined configuration. When workloads are added, updated, or removed, Thoras automatically manages the lifecycle of the associated AIScaleTargets.Use Cases
- Apply AI-powered scaling to all workloads with a specific label (e.g.,
thoras.ai/enabled: "true") - Standardize scaling policies across multiple microservices
- Automatically enable AI scaling for new workloads as they’re deployed
- Manage scaling configuration for entire application tiers or environments
Basic Example
env: production and thoras.ai/enabled: "true".
Specification
ClusterAIScaleTemplateSpec
| Field | Type | Required | Description |
|---|---|---|---|
selector | metav1.LabelSelector | Yes | Matches workloads to apply this template to. Supports matchLabels and matchExpressions. |
template | AIScaleTemplateSpec | Yes | Defines the AIScaleTarget configuration to apply. |
policy | TemplatePolicy | No | Controls template application behavior. |
AIScaleTemplateSpec
The template spec contains the same fields as AIScaleTarget spec, minus thescaleTargetRef
(which is automatically populated based on the matched workload):
| Field | Type | Required | Description |
|---|---|---|---|
model | ModelSpec | Yes | Model configuration (mode, forecast settings, buffer percentage). |
vertical | VerticalSpec | No | Vertical scaling configuration. |
horizontal | HorizontalSpec | No | Horizontal scaling configuration. |
TemplatePolicy
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
conflictResolution | string | No | skip | How to handle conflicts with existing AIScaleTargets. Options: skip, override. |
excludedNamespaces | []string | No | [kube-node-lease, kube-public, kube-system] | Namespaces where this template should not be applied. |
Behavior
Automatic AIScaleTarget Creation
When a workload (Deployment, StatefulSet, or Argo Rollout) matches the template’s selector:- Thoras creates an AIScaleTarget with the name
<workload-name>-ast - The AIScaleTarget is labeled with
thoras.ai/managed-by-template: <template-name> - The AIScaleTarget has an owner reference to the workload (so it’s deleted when the workload is deleted)
- The
scaleTargetRefis automatically populated with the workload’s details
Lifecycle Management
- Workload Created: AIScaleTarget is automatically created
- Workload Updated: If labels change and no longer match, the AIScaleTarget is deleted
- Workload Deleted: AIScaleTarget is automatically deleted via owner reference
- Template Updated: All managed AIScaleTargets are updated to match the new template
- Template Deleted: All managed AIScaleTargets are automatically deleted
Conflict Resolution
If an AIScaleTarget already exists with the same name:skip(default): The template will not modify the existing AIScaleTarget. This prevents overriding manually created or differently managed AIScaleTargets.override: Currently not implemented. The template will skip AIScaleTargets not managed by itself.
thoras.ai/managed-by-template label to determine
ownership. Only AIScaleTargets created by that specific template will be updated
or deleted by it.
Namespace Exclusions
By default, the following system namespaces are excluded:kube-node-leasekube-publickube-system
policy.excludedNamespaces field.
Advanced Examples
Using matchExpressions
Multiple Templates
You can create multiple templates with different selectors for different workload categories:Status and Monitoring
ClusterAIScaleTemplate includes a status subresource with conditions to track reconciliation state:Condition Types
| Type | Status | Reason | Description |
|---|---|---|---|
| Ready | True | ReconciliationSucceeded | Template successfully reconciled all namespaces |
| Ready | False | ReconciliationFailed | Failed to reconcile one or more namespaces |
| Ready | False | NamespaceListFailed | Failed to list namespaces |
Best Practices
-
Use Specific Selectors: Use precise label selectors to avoid unintended
matches. Consider using a dedicated label like
thoras.ai/enabled: "true"on workloads you want to scale. - Test in Non-Production First: Create a template in a development environment first to verify the selector matches the intended workloads.
- Monitor Template Status: Regularly check the template’s status conditions to ensure successful reconciliation.
- Namespace Exclusions: Always exclude system namespaces and any namespaces where automated scaling could cause issues.
-
Template Naming: Use descriptive names that indicate the purpose or scope
(e.g.,
production-frontend,staging-all-services). -
Label Workloads Explicitly: Rather than relying on existing labels, add a
specific label to workloads you want managed by templates (e.g.,
thoras.ai/template: "production-workloads"). - Avoid Overlapping Templates: Ensure template selectors don’t overlap in ways that would cause multiple templates to match the same workloads.
Troubleshooting
Template Not Creating AIScaleTargets
-
Check the template status:
-
Verify workloads match the selector:
-
Check if namespace is excluded:
-
View operator logs:
AIScaleTarget Not Updating When Template Changes
Ensure the AIScaleTarget has thethoras.ai/managed-by-template label:
Deleting Template But AIScaleTargets Remain
Check if the finalizer is stuck:Migration from Manual AIScaleTargets
To migrate existing manually created AIScaleTargets to template management:- Create a ClusterAIScaleTemplate with the desired configuration
- Add matching labels to your workloads
- The template will skip existing AIScaleTargets (due to default
skipconflict resolution) - Manually delete existing AIScaleTargets - they will be automatically recreated by the template
- Verify new AIScaleTargets have the
thoras.ai/managed-by-templatelabel
Related Documentation
- AIScaleTarget Definition - Complete reference for AIScaleTarget specifications
- Configuring AIScaleTargets - Step-by-step guide for creating AIScaleTargets
- Forecasting - Understanding how Thoras forecasts resource needs
- Predictive Horizontal Pod Autoscaling - Guide to horizontal scaling configuration
- Predictive Vertical Pod Rightsizing - Guide to vertical scaling configuration
- Enabling Autonomous Mode - Prerequisites for autonomous scaling