This is the 23rd day of my participation in Gwen Challenge

Twenty HeapSter monitor (deprecating)

Kubectl top is a built-in k8S command to view POD monitoring information. It obtains data from HeapSter, which is the monitoring software running at the K8S cluster level.

Kubectl has a built-in plugin called cAdvisor that collects resource usage on nodes and pods on nodes. HeapSter can collect data collected by cAdvisor on each node that it wants to store continuously. Data must then be placed in a DATABASE with influx DB, which can then be configured as a data source using Grafana and then displayed.

  • Heapster official project
https://github.com/kubernetes-retired/heapster
Copy the code

20.1 Installing INFLUX DB

Influx DB is a sequential database that requires a persistent store to hold data, so be aware that the official default emptyDir should be changed to a volume with persistent storage capability in its manifest file.

  • heapster/deploy/kube-config/influxdb/influxdb.yaml
apiVersion: apps/v1                     # change this to apps/v1, so you need to change the tag selector
kind: Deployment
metadata:
  name: monitoring-influxdb
  namespace: kube-system
spec:
  replicas: 1
  selector:                             # add a tag
    matchLables:                        # add a tag
      task: monitoring                  # add a tag
      k8s-app: influxdb                 # add a tag
  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: {}                    # this should be changed to persistent storage
---
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

Copy the code
  • Look at service and POD
$kubectl get SVC -n kube-system NAME TYPE cluster-ip external-ip PORT(S) AGE kube-DNS ClusterIP 10.96.0.10 <none> 10.109.5.194 < None > 443:30894/TCP 3D14H monitoring- Influxdb ClusterIP 10.104.173.236 < None > 8086/TCP 18s $kubectl get pod -n kube-system NAME READY STATUS RESTARTS AGE..... monitoring-influxdb-866db5f944-d7rkd 1/1 Running 0 69sCopy the code

20.2 installation HeapSter

  • The user who first installed RBAC, heapster/deploy/kube-config/rbac/heapster-rbac.yaml
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
  name: heapster
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: system:heapster
subjects:
- kind: ServiceAccount
  name: heapster
  namespace: kube-system
Copy the code
  • Installation heapster heapster/deploy/kube – config/influxdb/heapster yaml
apiVersion: v1
kind: ServiceAccount
metadata:
  name: heapster
  namespace: kube-system
---
apiVersion: apps/v1                    # change this to apps/v1, then need to add selector
kind: Deployment
metadata:
  name: heapster
  namespace: kube-system
spec:
  replicas: 1
  selector:                           # add it because you need to change the API version
    matchLabels:                      # add
      task: monitoring                # add
      k8s-app: heapster               # add
  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
    kubernetes.io/cluster-service: 'true'
    kubernetes.io/name: Heapster
  name: heapster
  namespace: kube-system
spec:
  ports:
  - port: 80
    targetPort: 8082
  selector:
    k8s-app: heapster
Copy the code
  • Kubectl get Pods-n kube-system
NAME                                    READY   STATUS    RESTARTS   AGE
...
heapster-5d4bf58946-6dmgf               1/1     Running   0          113s
monitoring-influxdb-866db5f944-d7rkd    1/1     Running   0          23m
Copy the code

20.3 installation Grafana

  • Install Grafana list: heapster/deploy/kube – config/influxdb/Grafana yaml
apiVersion: apps/v1                Change this to apps/v1
kind: Deployment
metadata:
  name: monitoring-grafana
  namespace: kube-system
spec:
  replicas: 1
  selector:                        # Because the API version is changed, so add this
    matchLabels:                   # tag selector
      task: monitoring             # tag selector
      k8s-app: grafana             # tag selector
  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              Configure the SSL certificate
      - name: grafana-storage
        emptyDir: {}                       Configure persistent storage
---
apiVersion: v1
kind: Service
metadata:
  labels:
    kubernetes.io/cluster-service: 'true'
    kubernetes.io/name: monitoring-grafana
  name: monitoring-grafana
  namespace: kube-system
spec:
  type: NodePort                         Heapster can be turned off if external access is required
  ports:
  - port: 80
    targetPort: 3000
  selector:
    k8s-app: grafana
Copy the code

other

Send your notes to: github.com/redhatxl/aw… Welcome one button three links