Kubernetes monitoring: Grafana plugins in Kubernetes

Source: Internet
Author: User
Tags grafana k8s cadvisor

Description: Use the Grafana official plugins (Grafana-kuberneres-app) Link Prometheus show kubernetes information
Note: All monitoring-related information is placed on the Namespace=monitor
Github:https://github.com/grafana/kubernetes-app
1, Installation Prometheus
Prom-rbac.yaml

apiVersion: rbac.authorization.k8s.io/v1beta1kind: ClusterRolemetadata:  name: prometheus  namespace: monitorrules:- apiGroups: [""]  resources:  - nodes  - nodes/proxy  - services  - endpoints  - pods  verbs: ["get", "list", "watch"]- apiGroups:  - extensions  resources:  - ingresses  verbs: ["get", "list", "watch"]- nonResourceURLs: ["/metrics"]  verbs: ["get"]---apiVersion: v1kind: ServiceAccountmetadata:  name: prometheus  namespace: monitor---apiVersion: rbac.authorization.k8s.io/v1beta1kind: ClusterRoleBindingmetadata:  name: prometheusroleRef:  apiGroup: rbac.authorization.k8s.io  kind: ClusterRole  name: prometheussubjects:- kind: ServiceAccount  name: prometheus  namespace: monitor

Cat Prom-config-kubernetes.yaml

Apiversion:v1kind:configmapmetadata:name:prometheus-config NAMESPACE:MONITORDATA:PROMETHEUS.YML: | Global:scrape_configs:-job_name: ' Kubernetes-kubelet ' Scheme:https tls_config:ca_file:/VAR/RUN/SECR ETS/KUBERNETES.IO/SERVICEACCOUNT/CA.CRT insecure_skip_verify:true bearer_token_file:/var/run/secrets/kubernete S.io/serviceaccount/token kubernetes_sd_configs:-Role:node relabel_configs:-Action:labelmap RE Gex: __meta_kubernetes_node_label_ (. +)-Target_label: __address__ REPLACEMENT:KUBERNETES.DEFAULT.SVC.CLUSTER.L Ocal:443-source_labels: [__meta_kubernetes_node_name] Regex: (. +) Target_label: __metrics_path__ R Eplacement:/api/v1/nodes/${1}/proxy/metrics-job_name: ' Kubernetes-cadvisor ' Scheme:https tls_config:c A_file:/var/run/secrets/kubernetes.io/serviceaccount/ca.crt insecure_skip_verify:true bearer_token_file:/var/ Run/secrets/kubernetes.io/serviceaccount/token kubernetes_sd_configs:-Role:node relabel_configs:-action:labelmap regex: __meta_kuberne Tes_node_label_ (. +)-Target_label: __address__ replacement:kubernetes.default.svc.cluster.local:443-sour Ce_labels: [__meta_kubernetes_node_name] Regex: (. +) Target_label: __metrics_path__ Replacement:/API/V1 /nodes/${1}/proxy/metrics/cadvisor-job_name: ' Kubernetes-kube-state ' kubernetes_sd_configs:-Role:pod RE Label_configs:-Action:labelmap regex: __meta_kubernetes_pod_label_ (. +)-Source_labels: [__meta_kubernete S_namespace] action:replace target_label:kubernetes_namespace-source_labels: [__meta_kubernetes_pod_na Me] action:replace target_label:kubernetes_pod_name-source_labels: [__meta_kubernetes_pod_label_grafan Ak8sapp] Regex:. *true.* action:keep-source_labels: [' __meta_kubernetes_pod_label_daemon ', ' __meta_kube  Rnetes_pod_node_name ']     Regex: ' Node-exporter; (. *) ' Action:replace target_label:nodename 

Cat Prom-install.yaml

Apiversion:v1kind:configmapmetadata:name:prometheus-config-test NAMESPACE:MONITORDATA:PROMETHEUS.YML: | Global:scrape_configs:-job_name: ' Kubernetes-kubelet ' Scheme:https tls_config:ca_file:/VAR/RUN/SECR ETS/KUBERNETES.IO/SERVICEACCOUNT/CA.CRT insecure_skip_verify:true bearer_token_file:/var/run/secrets/kubernete S.io/serviceaccount/token kubernetes_sd_configs:-Role:node relabel_configs:-Action:labelmap RE Gex: __meta_kubernetes_node_label_ (. +)-Target_label: __address__ REPLACEMENT:KUBERNETES.DEFAULT.SVC.CLUSTER.L Ocal:443-source_labels: [__meta_kubernetes_node_name] Regex: (. +) Target_label: __metrics_path__ R Eplacement:/api/v1/nodes/${1}/proxy/metrics-job_name: ' Kubernetes-cadvisor ' Scheme:https tls_config:c A_file:/var/run/secrets/kubernetes.io/serviceaccount/ca.crt insecure_skip_verify:true bearer_token_file:/var/ Run/secrets/kubernetes.io/serviceacCount/token kubernetes_sd_configs:-Role:node relabel_configs:-action:labelmap regex: __meta_ku  Bernetes_node_label_ (. +)-Target_label: __address__ replacement:kubernetes.default.svc.cluster.local:443- Source_labels: [__meta_kubernetes_node_name] Regex: (. +) Target_label: __metrics_path__ Replacement:/A     Pi/v1/nodes/${1}/proxy/metrics/cadvisor-job_name: ' Kubernetes-kube-state ' kubernetes_sd_configs:-role:pod Relabel_configs:-Action:labelmap regex: __meta_kubernetes_pod_label_ (. +)-Source_labels: [__meta_kube Rnetes_namespace] action:replace target_label:kubernetes_namespace-source_labels: [__meta_kubernetes_p Od_name] action:replace target_label:kubernetes_pod_name-source_labels: [__meta_kubernetes_pod_label_g Rafanak8sapp] Regex:. *true.* action:keep-source_labels: [' __meta_kubernetes_pod_label_daemon ', ' __meta _kubernetes_pod_node_namE '] regex: ' Node-exporter; (. *) ' Action:replace target_label:nodename-job_name: ' Tomcat-pods ' K  Ubernetes_sd_configs:-role:pod relabel_configs:-source_labels: [__meta_kubernetes_namespace] Regex: Tomcat action:keep-source_labels: [__meta_kubernetes_pod_container_port_number] regex:1234 ACTI On:keep-source_labels: [__meta_kubernetes_pod_name] Action:replace target_label:kubernetes_pod_name[[ Email protected] monitor]# cat Prom/prom-install.yaml apiversion:extensions/v1beta1kind:deploymentmetadata: Labels:name:prometheus Name:prometheus namespace:monitorspec:replicas:1 Template:metadata:labels:app : Prometheus-server spec:serviceAccountName:prometheus Containers:-Name:prometheus image:hub.llzg.co M.cn/monitor/prometheus:latest imagepullpolicy:always Ports:-containerport:9090 PROTOCOL:TC P volumemounts:-MOuntpath: "/etc/prometheus" Name:config-prometheus imagepullsecrets:-NAME:AUTHLLZG volumes:-nam E:config-prometheus Configmap:name:prometheus-config

Cat Prom-svc.yaml

kind: ServiceapiVersion: v1metadata:  name: prometheus-ingress-service  namespace: monitorspec:  selector:     app: prometheus-server  ports:    - protocol: TCP      port: 9090      name: prom---apiVersion: extensions/v1beta1kind: Ingressmetadata:  name: prom-web-ui  namespace: monitorspec:  rules:  - host: prom.name.com.cn    http:      paths:      - path: /        backend:          serviceName: prometheus-ingress-service          servicePort: prom

2, Installation State-metrics
Cat State-metrics-rbac.yaml

Apiversion:v1kind:serviceaccountmetadata:name:kube-state-metrics namespace:monitor---apiVersion: Rbac.authorization.k8s.io/v1kind:rolemetadata:namespace:monitor name:kube-state-metrics-resizerrules:-apiGroups : [""] resources:-pods verbs: ["get"]-apigroups: ["Extensions"] resources:-Deployments resourcenames: ["kube-st Ate-metrics "] Verbs: [" Get "," Update "]---apiversion:rbac.authorization.k8s.io/v1kind:rolebindingmetadata:name: Kube-state-metrics Namespace:monitorroleRef:apiGroup:rbac.authorization.k8s.io Kind:role name:kube-state-metrics- resizersubjects:-kind:serviceaccount name:kube-state-metrics namespace:monitor---apiVersion: Rbac.authorization.k8s.io/v1kind:clusterrolemetadata:name:kube-state-metrics namespace:monitorrules:-apiGroups: ["] Resources:-Nodes-pods-services-resourcequotas-replicationcontrollers-limitranges-persistentvolu Meclaims-persistentvolumes-namespaces-endpoints verbs: ["list", "watCh "-Apigroups: [" Extensions "] resources:-daemonsets-deployments-replicasets verbs: [" list "," Watch "]-Apigrou  PS: ["apps"] resources:-statefulsets verbs: ["list", "Watch"]-apigroups: ["Batch"] resources:-Cronjobs-jobs Verbs: ["list", "Watch"]-apigroups: ["autoscaling"] resources:-horizontalpodautoscalers verbs: ["list", "watch"]---A Piversion:rbac.authorization.k8s.io/v1 Kind:clusterrolebindingmetadata:name:kube-state-metrics namespace: MonitorroleRef:apiGroup:rbac.authorization.k8s.io kind:clusterrole name:kube-state-metricssubjects:-Kind:service Account Name:kube-state-metrics namespace:monitor---{"apiversion": "Apps/v1beta1", "kind": "Deployment", "metadata        ": {" name ":" Kube-state-metrics "," namespace ":" Monitor "}," spec ": {" selector ": {" Matchlabels ": { "K8s-app": "Kube-state-metrics", "Grafanak8sapp": "True"}, "Replicas": 1, "template": {"M     Etadata ": {" labels ": {     "K8s-app": "Kube-state-metrics", "Grafanak8sapp": "True"}, "spec": {"Serviceacco Untname ":" Kube-state-metrics "," containers ": [{" Name ":" Kube-state-metrics "," ima GE ":" hub.llzg.com.cn/monitor/kube-state-metrics:v1.1.0 "," ports ": [{" Name ":" Htt              P-metrics "," Containerport ": 8080}]," Readinessprobe ": { "HttpGet": {"path": "/healthz", "Port": 8080}, "Initialdelayseco            NDS ": 5," Timeoutseconds ": 5}]," Imagepullsecrets ": [{ ' Name ': ' Authllzg '}]}}}

3, installing Node-exporter
Cat Node-exporter.yaml

{"Kind": "Daemonset", "apiversion": "Extensions/v1beta1", "metadata": {"name": "Node-exporter", "namespace": "M Onitor "}," spec ": {" selector ": {" Matchlabels ": {" daemon ":" Node-exporter "," Grafanak8sapp ":" T Rue "}}," template ": {" metadata ": {" name ":" Node-exporter "," labels ": {" daemon "            : "Node-exporter", "Grafanak8sapp": "True"}, "spec": {"volumes": [{ "Name": "Proc", "Hostpath": {"path": "/proc"}}, {" Name ":" sys "," Hostpath ": {" path ":"/sys "}}]," containers ":            [{"Name": "Node-exporter", "image": "hub.llzg.com.cn/monitor/node-exporter:v0.15.0", "Args": ["--path.procfs=/proc_host", "--path.sysfs=/host_sys"], " Ports ": [{                "Name": "Node-exporter", "Hostport": 9100, "Containerport": 9100 }], "volumemounts": [{"name": "sys", "readOnly": Tru E, "Mountpath": "/host_sys"}, {"Name": "Proc", "R Eadonly ": True," Mountpath ":"/proc_host "}]," Imagepullpolicy ":" Ifnot    Present "}]," Restartpolicy ":" Always "," hostnetwork ": True," Hostpid ": true} }  }}

4, install Grafana (add Grafana-kubernetes-app plugin)
Cat Grafana.yaml

Apiversion:extensions/v1beta1kind:deploymentmetadata:labels:name:grafana-server Name:grafana namespace: Monitorspec:replicas:1 Template:metadata:labels:app:grafana-server Spec:serviceAccountName:promet Heus containers:-Name:grafana image:hub.llzg.com.cn/monitor/grafana:latest ports:-Containerpo rt:3000 protocol:tcp volumemounts:-Mountpath: "/var/lib/grafana" Readonly:false name : Grafana-nfs env:-Name:gf_install_plugins value: "Grafana-kubernetes-app" Imagepullsecrets:-N AME:AUTHLLZG volumes:-Name:grafana-nfs nfs:server:192.168.10.28 path: "/data/nfs/monitor/graf Ana "---kind:serviceapiversion:v1metadata:name:grafana-ingress-service namespace:monitorspec:selector:app:gra Fana-server ports:-protocol:tcp port:3000 Name:grafana---Apiversion:extensions/v1beta1kind:ingressmet Adata:name:grafana-ingress NameSpace:monitor annotations:kubernetes.io/ingress.class:traefikspec:rules:-host:grafana.llzg.com.cn http: Paths:-Path:/Backend:servicename:grafana-ingress-service Serviceport:grafana

5, Grafana+prometheus Monitor display kubernetes
(1) Grafana add Prometheus

(2) Loading Grafana-kubernetes-app plug-in
Configuration---->plugins--------->kubernetes
(3) Configuring the Grafana-kubernetes-app plugin

4, OK, go to see the picture bar

Kubernetes monitoring: Grafana plugins in Kubernetes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.