运行kubernetes autoscalar

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

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运行命令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 

我在这里错过了什么?

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

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

如何使用Kubernetes集群运行Heapster

我把这里的所有文件https://gitlab.com/abushoeb/kubernetes/tree/master/heapster 。 他们从官方的Kubernetes Repository收集,并做了一些小改动。

如何运行Heapster

转到目录heapster,你有grafana.yaml,heapster.yaml和influxdb.yaml,并运行以下命令$ kubectl create -f .

如何停止Heapster

转到相同的heapster目录,然后运行以下命令$ kubectl delete -f .

如何检查Heapster正在运行

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

如果您看到度量列表,那么hepaster运行正常。 您也可以浏览grafana仪表板来查看它(查找grafana正在运行的pod的IP,并访问它的http:// grafana-pod-ip:grafana-service-port )。

Heapster公制模型的完整文档在这里是可用的。

也只是运行($ kubectl集群信息),看看它是否显示这样的结果:

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是否有数据。 在本地机器上安装Influxdb客户端以连接到infuxdb数据库。 $ influx -host <cluster-ip> -port <influxdb-service-port>

一些示例influxdb查询

  • 显示数据库
  • 使用db-name
  • 显示测量
  • 从“cpu / node_capacity”中select值

参考和帮助