In earlier versions Kubernetes provides heapster, influxDB, combined grafana to the monitoring system, now more popular monitoring tools are prometheus, prometheus Google internal monitoring alarm system is an open source version
Prometheus compared to other traditional monitoring tools mainly has the following characteristics:
has a metric name and key / value pairs multidimensional data model time series data identified
a flexible query language
does not depend on distributed storage, and only about a local disk
HTTP service by pulling time series data
also support push way to add time-series data
also support the static configuration or through service discovery to find the target
a variety of graphics and support dashboards
Prometheus comprised of multiple components, but many components of which are optional:
Prometheus Server: index for gripping, storing time series data
exporter: Exposure Level Task catch so
pushgateway: push manner push the index data gateway
alertmanager : process alarms alert component
an adhoc: a data query
1, create a separate namespace
apiVersion: v1
kind: Namespace
metadata:
name: kube-ops
2, management profiles prometheus.yml in the form of configmap
apiVersion: v1
kind: ConfigMap
metadata:
name: prometheus-config
namespace: kube-ops
data:
prometheus.yml: |
global:
scrape_interval: 15s
scrape_timeout: 15s
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']
Prometheus.yml profile contains three modules: global, rule_files scrape_configs and
wherein the global control global Prometheus Server module configuration
rule_files position rule modules developed where, according to this configuration Prometheus loading rules for generating a new time series data or alarm information, currently we do not have to configure any rules
scrape_configs used to control prometheus monitor what resources.
There are in the default configuration in a single job, is called prometheus, which collected time-series data prometheus service itself. This job contains a single, static target configuration: listening on port 9090 of localhost.
prometheus default metrics collected by / metrics path targets. So, by default the job the URL of: HTTP: // localhost: 9090 / metrics collected metrics.
3, Configuration certification rbac
apiVersion: v1
kind: ServiceAccount
metadata:
name: prometheus
namespace: kube-ops
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: prometheus
rules:
- apiGroups:
- ""
resources:
- nodes
- services
- endpoints
- pods
- nodes/proxy
verbs:
- get
- list
- watch
- apiGroups:
- ""
resources:
- configmaps
- nodes/metrics
verbs:
- get
- nonResourceURLs:
- /metrics
verbs:
- get
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
name: prometheus
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: prometheus
subjects:
- kind: ServiceAccount
name: prometheus
namespace: kube-ops
4, the configuration data for pv pvc and persistence
apiVersion: v1
kind: PersistentVolume
metadata:
name: prometheus
spec:
capacity:
storage: 10Gi
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Recycle
nfs:
server: 192.168.1.244
path: /data/k8s
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: prometheus
namespace: kube-ops
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
5, create prometheus the Pod resource
$ docker pull prom / prometheus: v2.4.3
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: prometheus
namespace: kube-ops
labels:
app: prometheus
spec:
template:
metadata:
labels:
app: prometheus
spec:
serviceAccountName: prometheus
containers:
- image: prom/prometheus:v2.4.3
name: prometheus
command:
- "/bin/prometheus"
args:
- "--config.file=/etc/prometheus/prometheus.yml"
- "--storage.tsdb.path=/prometheus"
- "--storage.tsdb.retention=24h"
- "--web.enable-admin-api" # 控制对admin HTTP API的访问,其中包括删除时间序列等功能
- "--web.enable-lifecycle" # 支持热更新,直接执行localhost:9090/-/reload立即生效
ports:
- containerPort: 9090
protocol: TCP
name: http
volumeMounts:
- mountPath: "/prometheus"
subPath: prometheus
name: data
- mountPath: "/etc/prometheus"
name: config-volume
resources:
requests:
cpu: 100m
memory: 512Mi
limits:
cpu: 100m
memory: 512Mi
securityContext:
runAsUser: 0
volumes:
- name: data
persistentVolumeClaim:
claimName: prometheus
- configMap:
name: prometheus-config
name: config-volume
POD -n Kube kubectl GET $-OPS
Prometheus-77d968648-w5j6z 1/1 Running 53 82d
6, create svc prometheus pod of
apiVersion: v1
kind: Service
metadata:
name: prometheus
namespace: kube-ops
labels:
app: prometheus
spec:
selector:
app: prometheus
type: NodePort
ports:
- name: web
port: 9090
targetPort: http
Svc -n Kube kubectl GET $-OPS
Prometheus NodePort 10.102.197.83 <none> 9090: 32619 / TCP
http://192.168.1.243:32619
Click to view the status ---- targets monitored directory status