0

我找不到任何关于应该在哪里指定行为部分的示例Kind: HorizontalPodAutoscaler

在文档中他们有这个部分,但我找不到任何应该适合的例子?

behavior:
  scaleDown:
    stabilizationWindowSeconds: 300
    policies:
    - type: Percent
      value: 100
      periodSeconds: 15
  scaleUp:
    stabilizationWindowSeconds: 0
    policies:
    - type: Percent
      value: 100
      periodSeconds: 15
    - type: Pods
      value: 4
      periodSeconds: 15
    selectPolicy: Max

auto-scaler.yml这是一个没有行为部分的示例

apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
  name: nginx
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: nginx
  minReplicas: 1
  maxReplicas: 10
  metrics:
  - type: Resource
    resource:
      name: cpu
      target:
        type: Utilization
        averageUtilization: 50
  - type: Resource
    resource:
      name: memory
      target:
        type: AverageValue
        averageValue: 100Mi
4

2 回答 2

2

具体谈论您的示例,您需要将您的.behavior定义部分粘贴到.spec如下所示:

apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
  name: nginx
spec:
  # <--- START ---> 
  behavior:
    scaleDown:
      stabilizationWindowSeconds: 300
      policies:
      - type: Percent
        value: 100
        periodSeconds: 15
    scaleUp:
      stabilizationWindowSeconds: 0
      policies:
      - type: Percent
        value: 100
        periodSeconds: 15
      - type: Pods
        value: 4
        periodSeconds: 15
      selectPolicy: Max
      # <--- END ---> 
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: nginx
  minReplicas: 1
  maxReplicas: 10
  metrics:
  - type: Resource
    resource:
      name: cpu
      target:
        type: Utilization
        averageUtilization: 50
  - type: Resource
    resource:
      name: memory
      target:
        type: AverageValue
        averageValue: 100Mi

请记住,Kubernetes v1.18 提供了此功能。

早期版本的 Kubernetes 会显示以下错误:

error: error validating "hpa.yaml": error validating data: ValidationError(HorizontalPodAutoscaler.spec): unknown field "behavior" in io.k8s.api.autoscaling.v2beta2.HorizontalPodAutoscalerSpec; if you choose to ignore these errors, turn validation off with --validate=false

至于旁注,您还可以查看:

  • $ kubectl autoscale
  • $ kubectl autoscale deployment nginx --min=1 --max=10 --cpu-percent=80<- 示例

创建一个自动缩放器,自动选择和设置在 Kubernetes 集群中运行的 pod 数量。


附加参考:

于 2020-12-18T13:02:03.827 回答
1

将其置于规范之下

可以在规范的行为部分中指定一个或多个扩展策略。 https://kubernetes.io/docs/tasks/run-application/horizo​​ntal-pod-autoscale/#scaling-policies

于 2020-12-17T14:53:32.910 回答