Skip to main content
Version: 2.7.1

Scale Management

1. Background

Scale management is used to adjust the replica count of the ShenYu Bootstrap deployment in Kubernetes. ShenYu Admin can scale by fixed time policies or by dynamic metric rules collected from Prometheus.

This feature is disabled by default. Enable it only when ShenYu Admin can access the Kubernetes API server and has permission to update the target Deployment scale subresource.

2. Configuration

Enable scale management in application.yml:

shenyu:
k8s:
scale:
enabled: true
monitor-interval: 10000
pool-size: 6
prometheus:
url: http://localhost:9090
queries:
cpu_usage: "sum(rate(container_cpu_usage_seconds_total{namespace='%s', pod=~'%s.*'}[5m]))"
memory_usage: "sum(container_memory_usage_bytes{namespace='%s', pod=~'%s.*'})"
request_count: "sum(rate(http_requests_total{namespace='%s', pod=~'%s.*'}[1m]))"
deployment:
name: "shenyu-bootstrap"
namespace: "shenyu"
apiServer: "https://127.0.0.1:6443"
token: "token"
caCertPath: "/etc/kubernetes/pki/ca.crt"

Configuration description:

NameDescription
shenyu.k8s.scale.enabledWhether to enable Kubernetes scale management. The default value is false.
shenyu.k8s.scale.monitor-intervalMetric polling interval in milliseconds.
shenyu.k8s.scale.pool-sizeThread pool size for scale monitoring tasks.
shenyu.k8s.prometheus.urlPrometheus server URL.
shenyu.k8s.prometheus.queriesPromQL templates used by metric rules.
shenyu.k8s.deployment.nameTarget Kubernetes Deployment name.
shenyu.k8s.deployment.namespaceNamespace of the target Deployment.
shenyu.k8s.deployment.apiServerKubernetes API server address.
shenyu.k8s.deployment.tokenService account token used to access the Kubernetes API server.
shenyu.k8s.deployment.caCertPathCA certificate path for the Kubernetes API server.

3. Fixed Scale Policies

Choose System Management -> Scale Management in ShenYu Admin.

Scale policies define a fixed number of Bootstrap replicas within a time range. The policy fields include:

FieldDescription
SortPolicy priority.
Status1 means enabled, 0 means disabled.
NumTarget number of Bootstrap replicas.
Begin TimeThe time when the policy starts to take effect.
End TimeThe time when the policy stops taking effect.

When an enabled policy is active, ShenYu Admin scales the target Deployment to the configured replica count.

4. Dynamic Scale Rules

Scale rules define upper and lower thresholds for metrics. The rule fields include:

FieldDescription
Metric NameMetric key. It must match a key under shenyu.k8s.prometheus.queries.
TypeMetric source type. 0 is ShenYu, 1 is Kubernetes, and 2 is others.
SortRule priority.
Status1 means enabled, 0 means disabled.
MinimumIf the collected metric value is lower than this value, ShenYu Admin scales down by one replica.
MaximumIf the collected metric value is higher than this value, ShenYu Admin scales up by one replica.

Dynamic scaling uses the Prometheus query configured for the metric name. The query template receives the target Kubernetes namespace and Deployment name.

5. Notes

  • Configure Kubernetes RBAC before enabling scale management. The token must be allowed to read and update the target Deployment scale.
  • Keep the metric name in scale rules consistent with the keys configured under shenyu.k8s.prometheus.queries.
  • Start with conservative thresholds and verify the scale history before using the feature in production.