Auto Scaling
一句话解释
Auto scaling automatically adjusts 数字的 运行实例 (pods, 服务器) based on current 加载.
用大白话说
Auto scaling is the ability of a system to automatically increase or decrease its capacity based on demand. When traffic is high, more instances are added. When traffic drops, instances are removed to save resources.
There are three types of auto scaling in Kubernetes: Horizontal — adds or removes Pods (scales out/in). This is the most common type. Vertical — increases or decreases CPU/memory per Pod (scales up/down). Cluster — adds or removes entire nodes (scales the cluster itself).
Auto scaling requires a metrics source (like Prometheus or the Kubernetes Metrics Server) to provide current CPU/memory usage or custom metrics. Based on these metrics, the scaler decides how many instances to run.
示例
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: my-app-hpa
spec:
scaleTargetRef:
kind: Deployment
name: my-app
minReplicas: 2
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 70这个 HPA scales my-app 部署之间 2 and 10 Pods 到 keep CPU usage 围绕 70%.
工作原理
- A metrics source collects CPU/memory or custom metrics.
- The auto scaler checks metrics at regular intervals.
- If metrics exceed the target, it adds more instances.
- If metrics are below the target, it removes instances (down to minReplicas).
常见混淆
容易混淆的对象: Manual Scaling
关键区别: Manual scaling 需要 human 到更改 replica 数量; auto scaling 做它 automatically based on metrics, responding 到加载更改 in 真实时间.
相关术语
解读错误信息
用大白话解释常见错误——什么意思、为什么发生、如何修复。