写点什么

Kubernetes 手记(20)- HeapSter 监控

用户头像
雪雷
关注
发布于: 1 小时前
Kubernetes手记(20)-  HeapSter监控

二十 HeapSter 监控(废弃中)

kubectl top 是 k8s 内置查看 POD 监控信息的命令,它是从 HeapSter 中取得数据,而 HeapSter 是运行在 K8S 集群级别的监控软件。


kubectl 有一个内置插件,叫 cAdvisor 它用来收集 node 节点和节点上的 POD 上的资源使用量,HeapSter 可以收集 cAdvisor 在每个节点上采集的数据,这些数据想要持续存储,那么就必须将数据放在 influx DB 的数据库中,然后可以使用 Grafana 配置 influx DB 为数据源,然后展示。


  • heapster 官方项目


https://github.com/kubernetes-retired/heapster
复制代码

20.1 安装 influx DB

influx DB 是一个时序数据库,它需要一个持久存储来保存数据,所以要注意的是在它的清单文件中应该将官方默认的 emptyDir 修改为具有持久存储能力的存储卷。


  • heapster/deploy/kube-config/influxdb/influxdb.yaml


apiVersion: apps/v1                     # 此处修改为 apps/v1,由于修改了此处所以还需要修改标签选择器kind: Deploymentmetadata:  name: monitoring-influxdb  namespace: kube-systemspec:  replicas: 1  selector:                             # 添加标签    matchLables:                        # 添加标签      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: v1kind: Servicemetadata:  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-systemspec:  ports:  - port: 8086    targetPort: 8086  selector:    k8s-app: influxdb
复制代码


  • 查看 service 和 pod


$ kubectl get svc -n kube-systemNAME                   TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                  AGEkube-dns               ClusterIP   10.96.0.10       <none>        53/UDP,53/TCP,9153/TCP   9dkubernetes-dashboard   NodePort    10.109.5.194     <none>        443:30894/TCP            3d14hmonitoring-influxdb    ClusterIP   10.104.173.236   <none>        8086/TCP                 18s
$ kubectl get pod -n kube-systemNAME READY STATUS RESTARTS AGE.....monitoring-influxdb-866db5f944-d7rkd 1/1 Running 0 69s
复制代码

20.2 安装 HeapSter

  • 首先安装 rbac 的用户,heapster/deploy/kube-config/rbac/heapster-rbac.yaml


kind: ClusterRoleBindingapiVersion: rbac.authorization.k8s.io/v1beta1metadata:  name: heapsterroleRef:  apiGroup: rbac.authorization.k8s.io  kind: ClusterRole  name: system:heapstersubjects:- kind: ServiceAccount  name: heapster  namespace: kube-system
复制代码


  • 安装 heapster,heapster/deploy/kube-config/influxdb/heapster.yaml


apiVersion: v1kind: ServiceAccountmetadata:  name: heapster  namespace: kube-system---apiVersion: apps/v1                    # 修改此处的为 apps/v1,修改此处以后还需要添加 selector kind: Deploymentmetadata:  name: heapster  namespace: kube-systemspec:  replicas: 1  selector:                           # 因为修改 api 版本所以需要添加    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: v1kind: Servicemetadata:  labels:    task: monitoring    kubernetes.io/cluster-service: 'true'    kubernetes.io/name: Heapster  name: heapster  namespace: kube-systemspec:  ports:  - port: 80    targetPort: 8082  selector:    k8s-app: heapster
复制代码


  • 查看结果,kubectl get pods -n kube-system


NAME                                    READY   STATUS    RESTARTS   AGE...heapster-5d4bf58946-6dmgf               1/1     Running   0          113smonitoring-influxdb-866db5f944-d7rkd    1/1     Running   0          23m
复制代码

20.3 安装 Grafana

  • 安装 Grafana 清单:heapster/deploy/kube-config/influxdb/grafana.yaml


apiVersion: apps/v1                # 修改此处为 apps/v1kind: Deploymentmetadata:  name: monitoring-grafana  namespace: kube-systemspec:  replicas: 1  selector:                        # 由于修改了 api 版本,所以增加此处    matchLabels:                   # 标签选择器      task: monitoring             # 标签选择器      k8s-app: grafana             # 标签选择器  template:    metadata:      labels:        task: monitoring        k8s-app: grafana    spec:      containers:      - name: grafana        image: k8s.gcr.io/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"        - 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          value: /      volumes:      - name: ca-certificates        hostPath:          path: /etc/ssl/certs              # 注意配置 ssl 证书      - name: grafana-storage        emptyDir: {}                       # 注意配置持久存储---apiVersion: v1kind: Servicemetadata:  labels:    kubernetes.io/cluster-service: 'true'    kubernetes.io/name: monitoring-grafana  name: monitoring-grafana  namespace: kube-systemspec:  type: NodePort                         # 如果需要通过外部访问可以打开,可以关闭 heapster 的此项  ports:  - port: 80    targetPort: 3000  selector:    k8s-app: grafana
复制代码

其他

自己将手记发在:https://github.com/redhatxl/awesome-kubernetes-notes欢迎一键三连

发布于: 1 小时前阅读数: 4
用户头像

雪雷

关注

stay hungry stay foolish 2019.08.16 加入

Devops,python,shell,云原生,云架构,kubernetes https://github.com/redhatxl

评论

发布
暂无评论
Kubernetes手记(20)-  HeapSter监控