3

我有一个使用以下规范运行的复制控制器:

apiVersion: v1
kind: ReplicationController
metadata:
  name: owncloud-controller
spec:
  replicas: 1
  selector:
    app: owncloud
  template:
    metadata:
      labels:
        app: owncloud
    spec:
      containers:
      - name: owncloud
        image: adimania/owncloud9-centos7
        ports:
          - containerPort: 80
        volumeMounts:
          - name: userdata
            mountPath: /var/www/html/owncloud/data
        resources:
          requests:
            cpu: 400m
      volumes:
        - name: userdata
          hostPath:
            path: /opt/data

现在我使用 autoscale 命令运行 hpa。

$ kubectl autoscale rc owncloud-controller --max=5 --cpu-percent=10

我还使用 kubernetes run 命令启动了 heapster。

$ kubectl run heapster --image=gcr.io/google_containers/heapster:v1.0.2 --command -- /heapster --source=kubernetes:http://192.168.0.103:8080?inClusterConfig=false --sink=log

毕竟,自动缩放从未启动。从日志中,似乎没有报告实际的 CPU 利用率。

$ kubectl describe hpa owncloud-controller
Name:               owncloud-controller
Namespace:          default
Labels:             <none>
Annotations:            <none>
CreationTimestamp:      Thu, 26 May 2016 14:24:51 +0530
Reference:          ReplicationController/owncloud-controller/scale
Target CPU utilization:     10%
Current CPU utilization:    <unset>
Min replicas:           1
Max replicas:           5
ReplicationController pods: 1 current / 1 desired
Events:
  FirstSeen LastSeen    Count   From                SubobjectPath   Type        Reason          Message
  --------- --------    -----   ----                -------------   --------    ------          -------
  44m       8s      92  {horizontal-pod-autoscaler }            Warning     FailedGetMetrics    failed to get CPU consumption and request: metrics obtained for 0/1 of pods
  44m       8s      92  {horizontal-pod-autoscaler }            Warning     FailedComputeReplicas   failed to get CPU utilization: failed to get CPU consumption and request: metrics obtained for 0/1 of pods

我在这里想念什么?

4

2 回答 2

1

很可能 heapster 在错误的命名空间(“默认”)中运行。HPA 期望 heapster 位于“kube-system”命名空间中。请将 --namespace=kube-system 添加到 kubectl run heapster 命令。

于 2016-05-31T19:49:16.953 回答
0

我在名称空间“kube-system”下安装了 hepaster,它工作正常。运行 heapster 后,在将 HPA 用于您的应用程序之前,请确保它正在运行。

如何使用 Kubernetes 集群运行 Heapster

我把所有文件都放在这里https://gitlab.com/abushoeb/kubernetes/tree/master/heapster。它们是从官方Kubernetes 存储库中收集的,并进行了微小的更改。

如何运行 Heapster

转到您拥有 grafana.yaml、heapster.yaml 和 influxdb.yaml 的目录 heapster 并运行以下命令

$ kubectl create -f  .

如何阻止赫普斯特

转到相同的 heapster 目录,然后运行以下命令

$ kubectl delete -f  .

如何检查 Heapster 是否正在运行

您可以从运行 heapster 的 pod 访问 heapster 度量模型,以确保 heapster 正常工作。可以通过网络浏览器访问 http://heapster-pod-ip:heapster-service-port/api/v1/model/metrics/。通过执行以下命令可以看到相同的结果。

$ curl -L http://heapster-pod-ip:heapster-service-port/api/v1/model/metrics/

如果您看到指标列表,则表明 heapster 运行正常。您还可以浏览 grafana 仪表板来查看它(找到运行 grafana 的 pod 的 ip 并访问它 http://grafana-pod-ip:grafana-service-port)。

Heapster Metric Model 的完整文档可在此处获得。

也只需运行 ($ kubectl cluster-info) 并查看它是否显示如下结果:

Kubernetes master 运行在 https://cluster-ip:6443

Heapster 在 https://cluster-ip:6443/api/v1/proxy/namespaces/kube-system/services/heapster 运行

kubernetes-dashboard 在 https://cluster-ip:6443/api/v1/proxy/namespaces/kube-system/services/kubernetes-dashboard 运行

Monitoring-grafana 在 https://cluster-ip:6443/api/v1/proxy/namespaces/kube-system/services/monitoring-grafana 运行

monitoring-influxdb 在 https://cluster-ip:6443/api/v1/proxy/namespaces/kube-system/services/monitoring-influxdb 运行

检查流入数据库

您还可以检查 influxdb 中是否有数据。在本地机器上安装 Influxdb 客户端以连接到 infuxdb 数据库。

$ influx -host <cluster-ip> -port <influxdb-service-port>

一些示例 influxdb 查询

  • 显示数据库
  • 使用数据库名称
  • 显示测量值
  • 从“cpu/node_capacity”中选择值

参考和帮助

于 2017-07-06T21:51:14.480 回答