1. 程式人生 > >Kubernetes集成Heapster監控

Kubernetes集成Heapster監控

Heapster

Heapster是容器集群監控和性能分析工具,天然的支持Kubernetes和CoreOS。
Kubernetes有個出名的監控agent—cAdvisor。在每個kubernetes Node上都會運行cAdvisor,它會收集本機以及容器的監控數據(cpu,memory,filesystem,network,uptime)。
在較新的版本中,K8S已經將cAdvisor功能集成到kubelet組件中。每個Node節點可以直接進行web訪問。

1、鏡像下載
[root@k8s_master ~]# docker pull ist0ne/heapster-grafana-amd64
[root@k8s_master ~]# docker pull ist0ne/heapster-amd64

[root@k8s_master ~]# docker pull ist0ne/heapster-influxdb-amd64:v1.1.1

2、下載Heapster,最新版本1.3.0
wget https://github.com/kubernetes/heapster/archive/v1.3.0.tar.gz
tar zxf v1.3.0.tar.gz

3、進入heapster-1.3.0/deploy/kube-config/influxdb/目錄
[[root@k8s_master heapster-1.3.0]# ls -latr deploy/kube-config/influxdb/
total 24
-rw-rw-r-- 1 root root 477 Mar 17 2017 influxdb-service.yaml

-rw-rw-r-- 1 root root 493 Mar 17 2017 influxdb-deployment.yaml
-rw-rw-r-- 1 root root 453 Mar 17 2017 heapster-service.yaml
-rw-rw-r-- 1 root root 521 Mar 17 2017 heapster-deployment.yaml
-rw-rw-r-- 1 root root 695 Mar 17 2017 grafana-service.yaml
-rw-rw-r-- 1 root root 1417 Mar 17 2017 grafana-deployment.yaml

4、修改配置文件對應的image:
grafana-deployment.yaml

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: monitoring-grafana
  namespace: kube-system
spec:
  replicas: 1
  template:
    metadata:
      labels:
        task: monitoring
        k8s-app: grafana
    spec:
      containers:
      - name: grafana
        image: docker.io/ist0ne/heapster-grafana-amd64:latest
        ports:
          - containerPort: 3000
            protocol: TCP
        volumeMounts:
        - mountPath: /var
          name: grafana-storage
        env:
        - name: INFLUXDB_HOST
          value: monitoring-influxdb
        - name: GRAFANA_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/proxy/namespaces/kube-system/services/monitoring-grafana/
          value: /
      volumes:
      - name: grafana-storage
        emptyDir: {}

heapster-deployment.yaml

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: heapster
  namespace: kube-system
spec:
  replicas: 1
  template:
    metadata:
      labels:
        task: monitoring
        k8s-app: heapster
    spec:
      containers:
      - name: heapster
        image: docker.io/ist0ne/heapster-amd64:latest
        imagePullPolicy: IfNotPresent
        command:
        - /heapster
        - --source=kubernetes:http://192.168.3.216:8080?inClusterConfig=false
        - --sink=influxdb:http://monitoring-influxdb:8086

influxdb-deployment.yaml

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: monitoring-influxdb
  namespace: kube-system
spec:
  replicas: 1
  template:
    metadata:
      labels:
        task: monitoring
        k8s-app: influxdb
    spec:
      containers:
      - name: influxdb
        image: docker.io/ist0ne/heapster-influxdb-amd64:v1.1.1
        volumeMounts:
        - mountPath: /data
          name: influxdb-storage
      volumes:
      - name: influxdb-storage
        emptyDir: {}

啟動服務
[root@k8s_master heapster-1.3.0]# kubectl create -f deploy/kube-config/influxdb/
刪除服務
[root@k8s_master heapster-1.3.0]# kubectl delete -f deploy/kube-config/influxdb/

查看pod
[root@k8s_master ~]# kubectl get pods --all-namespaces

NAMESPACE     NAME                                    READY     STATUS    RESTARTS   AGE
default       busybox                                 1/1       Running   93         3d
kube-system   heapster-4127054459-wzppn               1/1       Running   0          3d
kube-system   kube-dns-2074712928-dxv2q               4/4       Running   4          3d
kube-system   kubernetes-dashboard-3665076642-9z0jc   1/1       Running   0          3d
kube-system   monitoring-grafana-597639858-tqpf2      1/1       Running   0          3d
kube-system   monitoring-influxdb-3575671003-9rpkh    1/1       Running   0          3d
web           nginx-491251965-dp4xz                   1/1       Running   2          4d
web           nginx-491251965-rjhhp                   1/1       Running   2          4d

打開瀏覽器http://192.168.3.216:8080/ui

技術分享圖片

技術分享圖片

Kubernetes集成Heapster監控