
Kubernetes 自动扩展(Autoscaling)是一种机制,它允许Kubernetes集群根据应用程序的需求动态调整资源。这包括自动扩展Pods(水平Pod自动扩展器,HPA)和自动扩展节点(集群自动扩展器,CA)。
创建HPA:
kubectl autoscale deployment <deployment-name> --min=2 --max=5 --cpu-percent=80
apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
name: example-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: <deployment-name>
minReplicas: 2
maxReplicas: 5
targetCPUUtilizationPercentage: 80
检查HPA状态:
kubectl get hpa