从基准测试工具接收负载时垂直 Pod 自动缩放器不工作

vertical pod autoscaler not working when receiving load from a benchmark tool

我有一个基于容器的应用程序,用于从基准测试工具接收负载并生成内存和 cpu 利用率。所以我为应用程序创建了这个部署文件:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: slave-leech-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: slave-leech-deployment
  template:
    metadata:
      labels:
        app: slave-leech-deployment
    spec:
      containers:
      - name: slave-leech
        image: kewynakshlley/slave-leech
        ports:
          - containerPort: 3000
        imagePullPolicy: Always
        resources:
          limits:
            cpu: 100m
            memory: 50Mi
          requests:
            cpu: 100m
            memory: 50Mi

我还有服务和垂直 Pod 自动缩放器清单:

服务:

kind: Service
metadata:
  name: slave-leech-deployment
spec:
  selector:
    app: slave-leech-deployment
  ports:
    - port: 80
      targetPort: 3000
  type: LoadBalancer```


vertical pod auto scaler manifest:

``` apiVersion: autoscaling.k8s.io/v1beta2
kind: VerticalPodAutoscaler
metadata:
  name: my-vpa
spec:
  targetRef:
    apiVersion: "apps/v1"
    kind:       Deployment
    name:       slave-leech-deployment
  updatePolicy:
    updateMode: "Auto"

当我 运行 基准工具时,我可以看到 cpu 利用率达到极限,但未触发 VPA,并且未使用更多资源重新创建容器。

cpu utilization

kubectl 的输出描述 vpa my-vpa

Namespace:    default
Labels:       <none>
Annotations:  kubectl.kubernetes.io/last-applied-configuration:
                {"apiVersion":"autoscaling.k8s.io/v1beta2","kind":"VerticalPodAutoscaler","metadata":{"annotations":{},"name":"my-vpa","namespace":"defaul...
API Version:  autoscaling.k8s.io/v1beta2
Kind:         VerticalPodAutoscaler
Metadata:
  Creation Timestamp:  2020-01-21T22:59:28Z
  Generation:          19
  Resource Version:    20357
  Self Link:           /apis/autoscaling.k8s.io/v1beta2/namespaces/default/verticalpodautoscalers/my-vpa
  UID:                 a5958daa-9274-4904-b706-bb81e4948599
Spec:
  Target Ref:
    API Version:  apps/v1
    Kind:         Deployment
    Name:         slave-leech-deployment
  Update Policy:
    Update Mode:  Recreate
Status:
  Conditions:
    Last Transition Time:  2020-01-21T23:00:07Z
    Message:               No pods match this VPA object
    Reason:                NoPodsMatched
    Status:                True
    Type:                  NoPodsMatched
    Last Transition Time:  2020-01-21T23:00:07Z
    Status:                True
    Type:                  RecommendationProvided
  Recommendation:
    Container Recommendations:
      Container Name:  slave-leech
      Lower Bound:
        Cpu:     25m
        Memory:  262144k
      Target:
        Cpu:     126m
        Memory:  262144k
      Uncapped Target:
        Cpu:     126m
        Memory:  262144k
      Upper Bound:
        Cpu:     1490m
        Memory:  428775530
Events: 
         <none>

Pod 的最大 CPU 利用率为 .097,小于 1 个核心,您的建议上限为 1490m(1.4 个核心),因此 VPA 不会重新安排。 The VerticalPodAutoscaler uses the lowerBound and upperBound recommendations to decide whether to delete a Pod and replace it with a new Pod. If a Pod has requests less than the lower bound or greater than the upper bound, the VerticalPodAutoscaler deletes the Pod and replaces it with a Pod that has the target recommendation

Vertical Pod Autoscaling

Understanding Resource Limits in Kubernetes

ffran09 的 his/her 答案是正确的,但我想添加更多信息。

正如我的评论中所述:

尝试 运行 此命令以查看 pods 上的确切 CPU 请求:

kubectl get pod -n dev -o=custom-columns=NAME:.metadata.name,PHASE:.status.phase,CPU-REQUEST:.spec.containers\[0\].resources.requests.cpu 

然后将其与您配置的建议进行比较。

这将帮助您观察实际的资源利用率,从而为您的 VPA 设置适当的限制。

我还建议您使用 metrics-server 来获取 pod 指标。 Minikube 将其作为捆绑的附加组件包含在内:

minikube addons enable metrics-server

有关 VPA 的该部分和其他重要元素的更多详细信息,我强烈建议您浏览这些资源:

如果有帮助,请告诉我。