This is a creation in
Article, where the information may have evolved or changed.
The default installation of Kubernetes dashboard, as shown, is not able to graphically display the cluster metrics information:
The implementation of the graphical presentation metrics requires the integration of another addons component of the k8s: Heapster.
Heapster native support for k8s (v1.0.6 and later) and CoreOS, and support a variety of storage backend, such as: InfluxDB, ElasticSearch, Kafka, and so on, this style and k8s is really like: the function of the first, whether perfect or not, First let oneself in each platform can use up again ^0^. The data storage backend we use here is influxdb.
First, installation steps
Our heapster is also to be run in the pod. Currently, Heapster's latest stable version is v1.2.0, and we can download its source package to a node on k8s cluster. After extracting, we get a directory named "Heapster-1.2.0″", enter the directory, we can see the following content:
root@node1:~/k8stest/dashboardinstall/heapster-1.2.0# lscode-of-conduct.md CONTRIBUTING.md docs Godeps hooks integration LICENSE metrics riemann versioncommon deploy events grafana influxdb kafka Makefile README.md vendor
Deploy Yaml under Deploy/kube-config/influxdb with INFLUXDB as the storage backend Heapster:
root@node1:~/k8stest/dashboardinstall/heapster-1.2.0# ls -l deploy/kube-config/influxdb/total 28-rw-r--r-- 1 root root 414 Sep 14 12:47 grafana-service.yaml-rw-r--r-- 1 root root 942 Jan 20 15:15 heapster-controller.yaml-rw-r--r-- 1 root root 249 Sep 14 12:47 heapster-service.yaml-rw-r--r-- 1 root root 1465 Jan 19 21:39 influxdb-grafana-controller.yaml-rw-r--r-- 1 root root 259 Sep 14 12:47 influxdb-service.yaml
There are five yaml (note: The latest code in the Heapster repository is different, and the latest code separates INFLUXDB and Grafana from Influxdb-grafana-controller.yaml). Some of these Docker image are outside the wall, if you have accelerators, then you can execute the CREATE command directly, otherwise it is better to find some alternatives: For example: Replace gcr.io/with Signalive/heapster_grafana:2.6.0-2 Google_containers/heapster_grafana:v2.6.0-2.
The operation to create the pod is simple:
~/k8stest/dashboardinstall/heapster-1.2.0# kubectl create -f deploy/kube-config/influxdb/service "monitoring-grafana" createdreplicationcontroller "heapster" createdservice "heapster" createdreplicationcontroller "influxdb-grafana" createdservice "monitoring-influxdb" created
If the image pull goes well, then these pods and service launches will be normal.
//kube get pods -n kube-system... ...kube-system heapster-b1dwa 1/1 Running 0 1h 172.16.57.9 10.46.181.146 k8s-app=heapster,version=v6kube-system influxdb-grafana-8c0e0 2/2 Running 0 1h 172.16.57.10 10.46.181.146 name=influxGrafana... ...
We open Kubernetes's dashboard with a browser, where is the expected graphical and clustered metrics information? Dashboard, as always, as shown in the above "simple", obviously we have a problem!
Second, troubleshooting
What's the problem? We need to look at the logs of the relevant pod individually:
# kubectl logs -f pods/influxdb-grafana-xxxxxx influxdb -n kube-system# kubectl logs -f pods/influxdb-grafana-xxxxxx grafana -n kube-system# kubectl logs -f pods/heapster-xxxxx -n kube-system
In the Heapster-xxxxx pod, we found a large number of failure logs:
E0119 13:14:37.838900 1 reflector.go:203] k8s.io/heapster/metrics/heapster.go:319: Failed to list *api.Pod: the server has asked for the client to provide credentials (get pods)E0119 13:14:37.838974 1 reflector.go:203] k8s.io/heapster/metrics/processors/node_autoscaling_enricher.go:100: Failed to list *api.Node: the server has asked for the client to provide credentials (get nodes)E0119 13:14:37.839516 1 reflector.go:203] k8s.io/heapster/metrics/processors/namespace_based_enricher.go:84: Failed to list *api.Namespace: the server has asked for the client to provide credentials (get namespaces)
Heapster cannot connect to Apiserver for information that you do not want. The log from Kube-apiserver (/var/log/upstart/kube-apiserver.log) also confirms this:
E0120 09:15:30.833928 12902 handlers.go:54] Unable to authenticate the request due to an error: crypto/rsa: verification errorE0120 09:15:30.834032 12902 handlers.go:54] Unable to authenticate the request due to an error: crypto/rsa: verification errorE0120 09:15:30.835324 12902 handlers.go:54] Unable to authenticate the request due to an error: crypto/rsa: verification error
From the Apiserver log, Heapster is connected via secure port of Apiserver, because our API server settings have HTTPS client side certificate verification mechanism, so the two connections fail.
Third, through the Insecure-port connection Kube-apiserver
Now we are going to solve this problem.
First, we will think: can let Heapster through Kube apiserver insecure-port connection? In the article "Security Configuration of the Kubernetes cluster" we mentioned that Kube-apiserver's request for Insecure-port access has no restriction mechanism so that heapster can get all the useful information it wants to get.
In "Configuring Source" in Heapster Doc, we found a way to connect Kube-apiserver insecure-port. But before we modify YAML, let's take a look at the implications of some of the current Heapster's startup configurations:
//deploy/kube-config/influxdb/heapster-controller.yamlcommand: - /heapster - --source=kubernetes:https://kubernetes.default - --sink=influxdb:http://monitoring-influxdb:8086
We see that Heapster starts with two startup parameters:
–source indicates the data source, Heapster is supported by a variety of data sources, here is the "kubernetes" type of data source, the address is: Kubernetes.default. The full name of this domain name is: kubernetes.default.svc.cluster.local, is the service "Kubernetes" in the cluster domain name, and "Kubernetes" The service is Kube-apiserver, and its information is as follows:
# kubectl get servicesNAME CLUSTER-IP EXTERNAL-IP PORT(S) AGEkubernetes 192.168.3.1
443/TCP 99d... ...# kubectl describe svc/kubernetesName: kubernetesNamespace: defaultLabels: component=apiserver provider=kubernetesSelector:
Type: ClusterIPIP: 192.168.3.1Port: https 443/TCPEndpoints: xxx.xxx.xxx.xxx:6443Session Affinity: ClientIPNo events.
Therefore, the domain name will be resolve as clusterip:192.168.3.1 in k8s DNS. The default port for HTTPS Plus is 443, so the apiserver address that Heapster actually tries to access is: https://192.168.3.1:443.
The other parameter that the Heapster starts is –sink, this incoming is the storage backend, we use the influxdb, here is the INFLUXDB service domain name and the port number which is created above, We can also find information about the service in cluster:
# kubectl get services -n kube-systemNAME CLUSTER-IP EXTERNAL-IP PORT(S) AGEmonitoring-influxdb 192.168.3.228
8083/TCP,8086/TCP 1h... ...
As mentioned earlier, our apiserver on secure port is a client-side certificate verification, then starting with such a startup parameter Heapster connection is not kube-apiserver "reasonable".
Next, we follow the method in "Configuring Source" to change the connection between Heapster and Kube-apiserver to the insecure port:
// kube-config/influxdb/heapster-controller.yaml... ...command: - /heapster - --source=kubernetes:http://10.47.136.60:8080?inClusterConfig=false - --sink=influxdb:http://monitoring-influxdb:8086
Re-create after modification. The log output of the Heapster pod after reboot is as follows:
# kubectl Logs-f pod/heapster-hco5i-n kube-systemi0120 02:03:46.014589 1 heapster.go:71]/heapster--source=kuber Netes:http://10.47.136.60:8080?inclusterconfig=false--sink=influxdb:http://monitoring-influxdb:8086i0120 02:03:46.014975 1 heapster.go:72] heapster version v1.3.0-beta.0i0120 02:03:46.015080 1 configs.go:60] Using K Ubernetes client with Master "http://10.47.136.60:8080" and version v1i0120 02:03:46.015175 1 configs.go:61] Using k Ubelet Port 10255E0120 02:03:46.025962 1 influxdb.go:217] issues while creating a influxdb sink:failed to ping Inf Luxdb server at "monitoring-influxdb:8086"-Get http://monitoring-influxdb:8086/ping:dial TCP 192.168.3.239:8086: Getsockopt:connection refused, would retry on useI0120 02:03:46.026090 1 influxdb.go:231] created influxdb sink with options:host:monitoring-influxdb:8086 user:root db:k8si0120 02:03:46.026214 1 heapster.go:193] Starting with Influ XDB SinkI0120 02:03:46.026286 1 heapster. go:193] Starting with Metric SinkI0120 02:03:46.051096 1 heapster.go:105] starting heapster on port 8082i0120 02:04 : 05.211382 1 influxdb.go:209] Created database "k8s" on Influxdb server at "monitoring-influxdb:8086"
The previous error has disappeared!
We open the dashboard again to see the pod information (we need to wait a little while, because it takes time to collect the cluster information), and we see the cluster metrics information graphically displayed in front of us (you can compare the illustration at the beginning of this article):
Iv. connecting Kube-apiserver via secure port
Kube-apiserver –insecure-port more for debugging, production environment but said off on, so through the Kube-apiserver secure port is the way of "lasting peace". But how do you do it? In the Heapster "Configure Source" gave a way to use the serviceaccount, but it is slightly more complicated ah. Here's a list of ways I've explored: using the Kubeconfig file! In the "Kubernetes cluster dashboard Plug-in Installation" article, we have configured the Kubeconfig file (the default location: ~/.kube/config), for kubeconfig configuration items are not very familiar with the children's shoes can be detailed reference to that article, This is not to be discussed here.
Next, we'll modify the Heapster-controller.yaml:
// deploy/kube-config/influxdb/heapster-controller.yaml... ...spec: containers: - name: heapster image: kubernetes/heapster:canary volumeMounts: - mountPath: /srv/kubernetes name: auth - mountPath: /root/.kube name: config imagePullPolicy: Always command: - /heapster - --source=kubernetes:https://kubernetes.default?inClusterConfig=false&insecure=true&auth=/root/.kube/config - --sink=influxdb:http://monitoring-influxdb:8086 volumes: - name: auth hostPath: path: /srv/kubernetes - name: config hostPath: path: /root/.kube... ...
From the contents of the above file –source we can see that we are back to the original Kubernetes service address: Https://kubernetes.default, but followed by a few parameters:
inClusterConfig=false : 不使用service accounts中的kube config信息;insecure=true:这里偷了个懒儿:选择对kube-apiserver发过来的服务端证书做信任处理,即不校验;auth=/root/.kube/config:这个是关键!在不使用serviceaccount时,我们使用auth文件中的信息来对应kube-apiserver的校验。
In the yaml above, we also mount two paths so that the pod can access the certificates under the appropriate configuration files (~/.kube/config) and/srv/kubernetes.
After saving and re-creating the relevant pod, the cluster metrics information under Dashboard can still be displayed graphically, so this method is OK!
, Bigwhite. All rights reserved.