【问题标题】:Horizontal Pod Autoscaler can't read CPU usageHorizo​​ntal Pod Autoscaler 无法读取 CPU 使用率
【发布时间】:2017-12-14 16:58:40
【问题描述】:

我不明白为什么我的水平 pod 自动缩放器无法从我的部署中读取 CPU 使用情况统计信息。

关于我的环境:

  • kubernetes 1.8.4 on AWS,使用 k8s 部署
  • 3 个节点和 1 个主节点
  • heapster 已安装(版本 1.5.0)并且正在工作(它在 influxdb 中写入数据,我可以在 grafana 中看到它)

以下是活动 HPA 的列表:

NAME       REFERENCE        TARGETS           MINPODS   MAXPODS   REPLICAS   AGE
api        Deployment/api   <unknown> / 70%   2         5         0          5h
web        Deployment/web   0% / 70%          2         5         2          22h

如您所见,只有一个 HPA 可以检测部署的资源使用情况。

web 部署(有效的):

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
labels:
    name: web
name: web
namespace: default
spec:
replicas: 1
selector:
    matchLabels:
    name: web
template:
    metadata:
    labels:
        name: web
    spec:
    containers:
    - image: <private repository image path>
        imagePullPolicy: IfNotPresent
        name: node
        ports:
        - containerPort: 3000
        protocol: TCP
        resources:
        limits:
            cpu: 200m
            memory: 200M
        requests:
            cpu: 200m
            memory: 200M

不起作用的api部署:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
labels:
    name: api
name: api
namespace: default
spec:
replicas: 1
selector:
    matchLabels:
    name: api
template:
    metadata:
    labels:
        app: api
    spec:
    containers:
        image: <private repository image path>
        imagePullPolicy: IfNotPresent
        name: node
        ports:
        - containerPort: 3000
        protocol: TCP
        resources:
        limits:
            cpu: 250m
            memory: 200M
        requests:
            cpu: 250m
            memory: 200M

网络 HPA(有效的):

apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
name: web
namespace: default
spec:
maxReplicas: 5
minReplicas: 2
scaleTargetRef:
    apiVersion: apps/v1beta1
    kind: Deployment
    name: web
targetCPUUtilizationPercentage: 70

api HPA(不起作用的那个):

apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
name: api
namespace: default
spec:
maxReplicas: 5
minReplicas: 2
scaleTargetRef:
    apiVersion: apps/v1beta2
    kind: Deployment
    name: api
targetCPUUtilizationPercentage: 70

正如您所见,部署和 hpa 几乎相同,这就是为什么我无法弄清楚为什么只有一个有效。 任何解决此问题的帮助将不胜感激

编辑

我只是尝试删除正在工作的 hpa 并重新应用它,但它也不起作用。这让我认为这是heapster的问题。 我更新到最新的 heapster 版本 (1.5.0) 但仍然没有运气。

【问题讨论】:

    标签: kubernetes


    【解决方案1】:

    原因可能是没有 pod 运行

    NAME       REFERENCE        TARGETS           MINPODS   MAXPODS   REPLICAS   AGE
    api        Deployment/api   <unknown> / 70%   2         5         0          5h
    web        Deployment/web   0% / 70%          2         5         2          22h
    

    由于 “api”的副本数为零,这意味着应用程序未运行,而“web”的副本数为 2。

    尝试检查 "kubectl get pods {namespace}" 是否有正在运行的 pod。

    【讨论】:

    • 不,replicas 是 HPA 评估的计算出的副本数。部署的实际副本目前设置为 1(因为它应该由 HPA 处理)。
    【解决方案2】:

    通过重启 kube-controller-manager pod,一切都重新开始工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-01-16
      • 1970-01-01
      • 2019-12-10
      • 1970-01-01
      • 2023-03-26
      • 2021-06-01
      • 2019-08-22
      • 2019-06-12
      相关资源
      最近更新 更多