我已经根据Running Kubernetes Locally via Docker指南在Ubuntu(可信任)上建立了Kubernetes集群,部署了DNS,并使用InfluxDB后端和Grafana UI运行Heapster。

除了Grafana之外,其他所有内容似乎都运行顺利,除了Grafana之外,图中没有显示任何图形,但消息No datapoints为:Screenshot

在检查Docker容器日志后,我发现Heapster无法访问kubelet API(?),因此没有任何度量标准可持久保存到InfluxDB中:

user@host:~$ docker logs e490a3ac10a8
I0701 07:07:30.829745       1 heapster.go:65] /heapster --source=kubernetes:https://kubernetes.default --sink=influxdb:http://monitoring-influxdb:8086
I0701 07:07:30.830082       1 heapster.go:66] Heapster version 1.2.0-beta.0
I0701 07:07:30.830809       1 configs.go:60] Using Kubernetes client with master "https://kubernetes.default" and version v1
I0701 07:07:30.831284       1 configs.go:61] Using kubelet port 10255
E0701 07:09:38.196674       1 influxdb.go:209] issues while creating an InfluxDB sink: failed to ping InfluxDB server at "monitoring-influxdb:8086" - Get http://monitoring-influxdb:8086/ping: dial tcp 10.0.0.223:8086: getsockopt: connection timed out, will retry on use
I0701 07:09:38.196919       1 influxdb.go:223] created influxdb sink with options: host:monitoring-influxdb:8086 user:root db:k8s
I0701 07:09:38.197048       1 heapster.go:92] Starting with InfluxDB Sink
I0701 07:09:38.197154       1 heapster.go:92] Starting with Metric Sink
I0701 07:09:38.228046       1 heapster.go:171] Starting heapster on port 8082
I0701 07:10:05.000370       1 manager.go:79] Scraping metrics start: 2016-07-01 07:09:00 +0000 UTC, end: 2016-07-01 07:10:00 +0000 UTC
E0701 07:10:05.008785       1 kubelet.go:230] error while getting containers from Kubelet: failed to get all container stats from Kubelet URL "http://127.0.0.1:10255/stats/container/": Post http://127.0.0.1:10255/stats/container/: dial tcp 127.0.0.1:10255: getsockopt: connection refused
I0701 07:10:05.009119       1 manager.go:152] ScrapeMetrics: time: 8.013178ms size: 0
I0701 07:11:05.001185       1 manager.go:79] Scraping metrics start: 2016-07-01 07:10:00 +0000 UTC, end: 2016-07-01 07:11:00 +0000 UTC
E0701 07:11:05.007130       1 kubelet.go:230] error while getting containers from Kubelet: failed to get all container stats from Kubelet URL "http://127.0.0.1:10255/stats/container/": Post http://127.0.0.1:10255/stats/container/: dial tcp 127.0.0.1:10255: getsockopt: connection refused
I0701 07:11:05.007686       1 manager.go:152] ScrapeMetrics: time: 5.945236ms size: 0
W0701 07:11:25.010298       1 manager.go:119] Failed to push data to sink: InfluxDB Sink
I0701 07:12:05.000420       1 manager.go:79] Scraping metrics start: 2016-07-01 07:11:00 +0000 UTC, end: 2016-07-01 07:12:00 +0000 UTC
E0701 07:12:05.002413       1 kubelet.go:230] error while getting containers from Kubelet: failed to get all container stats from Kubelet URL "http://127.0.0.1:10255/stats/container/": Post http://127.0.0.1:10255/stats/container/: dial tcp 127.0.0.1:10255: getsockopt: connection refused
I0701 07:12:05.002467       1 manager.go:152] ScrapeMetrics: time: 1.93825ms size: 0
E0701 07:12:12.309151       1 influxdb.go:150] Failed to create infuxdb: failed to ping InfluxDB server at "monitoring-influxdb:8086" - Get http://monitoring-influxdb:8086/ping: dial tcp 10.0.0.223:8086: getsockopt: connection timed out
I0701 07:12:12.351348       1 influxdb.go:201] Created database "k8s" on influxDB server at "monitoring-influxdb:8086"
I0701 07:13:05.001052       1 manager.go:79] Scraping metrics start: 2016-07-01 07:12:00 +0000 UTC, end: 2016-07-01 07:13:00 +0000 UTC
E0701 07:13:05.015947       1 kubelet.go:230] error while getting containers from Kubelet: failed to get all container stats from Kubelet URL "http://127.0.0.1:10255/stats/container/": Post http://127.0.0.1:10255/stats/container/: dial tcp 127.0.0.1:10255: getsockopt: connection refused
...

我在GitHub上发现了一些描述类似问题的问题,这些问题使我了解到,Heapster并不访问kubelet(通过节点的环回),而是本身(通过容器的环回)。但是,我无法重现他们的解决方案:

github.com/kubernetes/heapster/issues/1183



-@ piosz
  • 如何为Heapster容器启用“主机联网”?
  • 如何配置群集/节点使用常规名称而不是127.0.0.1?

  • github.com/kubernetes/heapster/issues/744



    -@ ddispaltro
  • 是否可以通过在docker run中添加/修改kubelet的选项标志来解决此问题?我尝试设置--hostname-override=<host's eth0 IP>--address=127.0.0.1(如该GitHub问题的最后一个答案所建议),但是Heapster的容器日志随后指出:I0701 08:23:05.000566 1 manager.go:79] Scraping metrics start: 2016-07-01 08:22:00 +0000 UTC, end: 2016-07-01 08:23:00 +0000 UTCE0701 08:23:05.000962 1 kubelet.go:279] Node 127.0.0.1 is not readyE0701 08:23:05.003018 1 kubelet.go:230] error while getting containers from Kubelet: failed to get all container stats from Kubelet URL "http://<host's eth0 IP>:10255/stats/container/": Post http://<host's eth0 IP>/stats/container/: dial tcp <host's eth0 IP>:10255: getsockopt: connection refused

  • 命名空间问题

    这个问题可能是由于我在default命名空间中运行Kubernetes API而在kube-system中运行Heapster引起的吗?
    user@host:~$ kubectl get --all-namespaces pods
    NAMESPACE     NAME                     READY     STATUS    RESTARTS   AGE
    default       k8s-etcd-127.0.0.1       1/1       Running   0          18h
    default       k8s-master-127.0.0.1     4/4       Running   1          18h
    default       k8s-proxy-127.0.0.1      1/1       Running   0          18h
    kube-system   heapster-lizks           1/1       Running   0          18h
    kube-system   influxdb-grafana-e0pk2   2/2       Running   0          18h
    kube-system   kube-dns-v10-4vjhm       4/4       Running   0          18h
    

    操作系统:Ubuntu 14.04.4 LTS(可信任)|
    Kubernetes:v1.2.5 |
    docker :v1.11.2

    最佳答案

    Heapster从Kubernetes获得了节点列表,现在正尝试从每个节点的Kublete进程中获取统计信息(该数据库在节点上具有内置的cAdvisor收集统计信息)。在这种情况下,只有一个节点,并且kubernetes被127.0.0.1所知道。还有问题。 Heapster容器正尝试到达127.0.0.1处的节点,该节点本身本身当然也没有找到在Heapster容器内进行查询的Kublete进程。

    解决此问题需要发生两件事。

  • 除了环回网络地址127.0.0.1
  • 外,我们还需要引用kublete worker节点(运行kubernetes的主机)。
  • kublete进程需要接受来自新网络接口(interface)/地址
  • 的流量

    假设您正在使用本地安装指南,并使用以下命令启动kubernetes
    hack/local-up-cluster.sh
    

    更改引用kublete的主机名非常简单。您可以采用更复杂的方法,但是将其设置为您的eth0 ip对我来说效果很好(ifconfig eth0)。缺点是您需要一个eth0接口(interface),该接口(interface)受DHCP的约束,因此您的便利程度可能会有所不同。
    export HOSTNAME_OVERRIDE=10.0.2.15
    

    要让kublete进程接受来自任何网络接口(interface)的流量,就很简单。
    export KUBELET_HOST=0.0.0.0
    

    关于docker - Heapster无法从Kubernetes集群上的Kubelet获取容器统计信息,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38142503/

    10-16 06:25