26.5. 为 CPU 使用率自动扩展
使用 oc autoscale 命令,并至少指定您要在任意给定时间运行的 pod 的最大数量。您可以选择指定 OpenShift Container Platform 服务器的 pod 的最小数量和 pod 的平均 CPU 使用率,否则这些利用率从 OpenShift Container Platform 服务器赋予默认值。
例如:
$ oc autoscale dc/frontend --min 1 --max 10 --cpu-percent=80
deploymentconfig "frontend" autoscaled
在使用 pod 横向自动扩展的 autoscaling/v1 版本时,上面的 pod 横向自动扩展使用以下定义:
例 26.1. Pod 横向自动扩展对象定义
apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
name: frontend
spec:
scaleTargetRef:
kind: DeploymentConfig
name: frontend
apiVersion: apps/v1
subresource: scale
minReplicas: 1
maxReplicas: 10
targetCPUUtilizationPercentage: 80
另外,oc autoscale 命令在使用 pod 横向自动扩展 v2beta1 版本时,会根据定义创建一个 pod 横向自动扩展:
apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
name: hpa-resource-metrics-cpu
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: ReplicationController
name: hello-hpa-cpu
minReplicas: 1
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
targetAverageUtilization: 50