HeapSter(k8s1.12版本已弃用)-influxdb+heapster+grafana

mac2025-10-17  6

kubelet能获取当前系统上收集管理的pos资源对象

kubelet中有个插件cAdvisor,专门负责收集当前节点上 各pod 各容器以及当前节点在节点级的各种系统级资源指标占用量,例如节点级的CPU、内存和pods级的CPU、内存用量。

cAdvisor只能收集单个节点的,另一个插件HeapSter则是负责收集每个节点中cAdvisor收集的数据。HeapSter数据存在缓存中,内存有限,只能缓存一段时间,如果要看历史的数据,则要用另一个插件,InfluxDB则是用于持久化存储的数据库,如果要查看InfluxDB的数据,则会用另一个插件Grafana,用于展示InfluxDB为数据源的数据。

部署InfluxDB

1)下载yaml wget https://raw.githubusercontent.com/kubernetes-retired/heapster/master/deploy/kube-config/influxdb/influxdb.yaml

搜索步骤:搜索heapster,进入deploy,再进入kube-config,选择influxdb;地址:https://github.com/kubernetes-retired/heapster/tree/master/deploy/kube-config

2)运行该yaml文件 或者可以改一下版本号,如下,修改了apiVersion以及加了个选择器

apiVersion: apps/v1 kind: Deployment metadata: name: monitoring-influxdb namespace: kube-system spec: replicas: 1 selector: matchLabels: task: monitoring k8s-app: influxdb template: metadata: labels: task: monitoring k8s-app: influxdb spec: containers: - name: influxdb image: k8s.gcr.io/heapster-influxdb-amd64:v1.5.2 volumeMounts: - mountPath: /data name: influxdb-storage volumes: - name: influxdb-storage emptyDir: {} --- apiVersion: v1 kind: Service metadata: labels: task: monitoring # For use as a Cluster add-on (https://github.com/kubernetes/kubernetes/tree/master/cluster/addons) # # If you are NOT using this as an addon, you should comment out this line. kubernetes.io/cluster-service: 'true' kubernetes.io/name: monitoring-influxdb name: monitoring-influxdb namespace: kube-system spec: ports: - port: 8086 targetPort: 8086 selector: k8s-app: influxdb

这里如果镜像下载不下来则可以先去搜索一下镜像,拉下来后打个tag

[root@master heapster]# docker search heapster-influxdb-amd64:v1.5.2 NAME DESCRIPTION STARS OFFICIAL AUTOMATED tianyong/heapster-influxdb-amd64 heapster-influxdb-amd64:v1.5.2 1 [OK] netonline/heapster-influxdb-amd64 gcr.io/google_containers/heapster-influxdb-a… 0 [OK] xxlaila/heapster-influxdb-amd64 heapster-influxdb-amd64:v1.5.2 0 [OK] heleicool/heapster-influxdb-amd64 k8s.gcr.io/heapster-influxdb-amd64:v1.5.2 0 mycontroldestiny/k8s docker push k8s.gcr.io/heapster-influxdb-amd… 0 mxpan/heapster-influxdb-amd64 heapster-influxdb-amd64:v1.5.2 0 [OK] fengzos/heapster-influxdb original from k8s.gcr.io/heapster-influxdb-a… 0 [OK] pingxiesean/heapster-influxdb-amd64 heapster-influxdb-amd64:v1.5.2 0 [OK] sniperwang/heapster-influxdb-amd64 gcr.io/google-containers/heapster-influxdb-a… 0 zuzhous/heapster-influxdb-amd64 k8s.gcr.io/heapster-influxdb-amd64:v1.5.2 0 [OK] dockerofwj/heapster-influxdb-amd64 k8s.gcr.io/heapster-influxdb-amd64:v1.5.2 0 [OK] daping/heapster-influxdb-amd64 k8s.gcr.io/heapster-influxdb-amd64:v1.5.2 0 optimism1207/heapster-influxdb-amd64 heapster-influxdb-amd64:v1.5.2 0 shanchaodev/heapster-influxdb-amd64 k8s.gcr.io/heapster-influxdb-amd64:v1.5.2 0 [root@master heapster]# docker pull tianyong/heapster-influxdb-amd64:v1.5.2 v1.5.2: Pulling from tianyong/heapster-influxdb-amd64 75a0e65efd51: Pull complete e621f97cbac9: Pull complete a81b82a53fcf: Pull complete Digest: sha256:2eb1c4f2509a37151e80171dccefef10108a89787e3aea22b96ccc4fc6ebebba Status: Downloaded newer image for tianyong/heapster-influxdb-amd64:v1.5.2 [root@master heapster]# docker tag tianyong/heapster-influxdb-amd64:v1.5.2 k8s.gcr.io/heapster-influxdb-amd64:v1.5.2

查看是否跑起来了

[root@master heapster]# kubectl get svc,pods -n kube-system | grep influxdb service/monitoring-influxdb ClusterIP 10.1.134.15 <none> 8086/TCP 16m pod/monitoring-influxdb-866db5f944-jjmzp 1/1 Running 0 16m

部署heapster 下载yaml,运行修改部分内容

apiVersion: v1 kind: ServiceAccount metadata: name: heapster namespace: kube-system --- apiVersion: extensions/v1beta1 kind: Deployment metadata: name: heapster namespace: kube-system spec: replicas: 1 selector: matchLabels: task: monitoring k8s-app: heapster template: metadata: labels: task: monitoring k8s-app: heapster spec: serviceAccountName: heapster containers: - name: heapster image: k8s.gcr.io/heapster-amd64:v1.5.4 imagePullPolicy: IfNotPresent command: - /heapster - --source=kubernetes:https://kubernetes.default - --sink=influxdb:http://monitoring-influxdb.kube-system.svc:8086 --- apiVersion: v1 kind: Service metadata: labels: task: monitoring # For use as a Cluster add-on (https://github.com/kubernetes/kubernetes/tree/master/cluster/addons) # # If you are NOT using this as an addon, you should comment out this line. kubernetes.io/cluster-service: 'true' kubernetes.io/name: Heapster name: heapster namespace: kube-system spec: ports: - port: 80 targetPort: 8082 type: NodePort selector: k8s-app: heapster

镜像可用之前的办法拉取,也可以直接修改镜像名称 查看pods是否正常运行,查看端口,然后浏览器访问,看到404说明服务已经可以访问到了。

[root@master heapster]# kubectl get pods -n kube-system | grep heapster heapster-5d4bf58946-t6hxq 1/1 Running 0 3m27s [root@master heapster]# kubectl get svc -n kube-system NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE heapster NodePort 10.1.228.2 <none> 80:32051/TCP 3m57s kube-dns ClusterIP 10.1.0.10 <none> 53/UDP,53/TCP,9153/TCP 4d3h kubernetes-dashboard NodePort 10.1.225.89 <none> 443:30002/TCP 4d2h monitoring-influxdb ClusterIP 10.1.134.15 <none> 8086/TCP 32m tiller-deploy ClusterIP 10.1.110.189 <none> 44134/TCP 3d

部署grafana 下载yaml文件,运行

apiVersion: extensions/v1beta1 kind: Deployment metadata: name: monitoring-grafana namespace: kube-system spec: replicas: 1 selector: matchLabels: task: monitoring k8s-app: grafana template: metadata: labels: task: monitoring k8s-app: grafana spec: containers: - name: grafana image: tianyong/heapster-grafana-amd64:v5.0.4 ports: - containerPort: 3000 protocol: TCP volumeMounts: - mountPath: /etc/ssl/certs name: ca-certificates readOnly: true - mountPath: /var name: grafana-storage env: - name: INFLUXDB_HOST value: monitoring-influxdb - name: GF_SERVER_HTTP_PORT value: "3000" # The following env variables are required to make Grafana accessible via # the kubernetes api-server proxy. On production clusters, we recommend # removing these env variables, setup auth for grafana, and expose the grafana # service using a LoadBalancer or a public IP. - name: GF_AUTH_BASIC_ENABLED value: "false" - name: GF_AUTH_ANONYMOUS_ENABLED value: "true" - name: GF_AUTH_ANONYMOUS_ORG_ROLE value: Admin - name: GF_SERVER_ROOT_URL # If you're only using the API Server proxy, set this value instead: # value: /api/v1/namespaces/kube-system/services/monitoring-grafana/proxy value: / volumes: - name: ca-certificates hostPath: path: /etc/ssl/certs - name: grafana-storage emptyDir: {} --- apiVersion: v1 kind: Service metadata: labels: # For use as a Cluster add-on (https://github.com/kubernetes/kubernetes/tree/master/cluster/addons) # If you are NOT using this as an addon, you should comment out this line. kubernetes.io/cluster-service: 'true' # If you are NOT using this as an addon, you should comment out this line. kubernetes.io/cluster-service: 'true' kubernetes.io/name: monitoring-grafana name: monitoring-grafana namespace: kube-system spec: # In a production setup, we recommend accessing Grafana through an external Loadbalancer # or through a public IP. # type: LoadBalancer # You could also use NodePort to expose the service at a randomly-generated port # type: NodePort ports: - port: 80 targetPort: 3000 type: NodePort selector: k8s-app: grafana

heapster在k8S 1.2版本后已弃用,所以部署好了也没用,不过至少知道了其中的一些原理

早期heapster时代,资源指标不是APIserver负责的,而是通过第三方应用。而一旦第三方不维护此应用,使用就会出现一些问题,因此,heapster将很多的第三方应用整合进了自己的系统,导致代码量庞大,最终大家发现heapster这种架构不适合k8s的架构体系,于是慢慢被淘汰。由于K8S使用的很多东西都是通过add-on的形式,所以更新换代不是很困难。

最新回复(0)