grafana+prometheus+metrics对kubernetes的监控配置⼀、监控选型
1. 选择⽤进⾏监控kubernetes。
2. ⽀持对k8s多集监控,操作简单。
3. ⽀持对应⽤的健康探测。
Requirements:
1. Currently only has support for
2. For automatic deployment of the exporters, then Kubernetes 1.6 or higher is required.
3. Grafana 5.0.0+
1)kube-state-metrics插件
2)node-exporter插件
3)prometheus插件
4)black-box-exporter插件
5)alertmanager插件
6)prometheus-webhook-dingtalk插件
⼆、布署
1、namspace: kube-system
2、rbac:
serviceaccount: prometheus
clusterrole: prometheus
clusterrolebinding: prometheus
---
apiVersion: rbac.authorization.k8s.io/v1beta1 kind: ClusterRole
metadata:
name: prometheus
rules:
- apiGroups: [""]
resources:
- nodes
- nodes/proxy
- services
- endpoints
- pods
verbs: ["get", "list", "watch"]
-
apiGroups: ["extensions", "apps"]
resources: ["deployments"]
verbs: ["get", "list", "watch"]
- apiGroups: ["batch", "extensions"]
resources: ["jobs"]
verbs: ["get", "list", "watch"]
- apiGroups:
- extensions
resources:
- ingresses
verbs: ["get", "list", "watch"]
-
nonResourceURLs: ["/metrics"]
verbs: ["get"]
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: prometheus
namespace: kube-system
---
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-system
---
3、deployment: prometheus
apiVersion: apps/v1
kind: Deployment
metadata:
name: prometheus-deployment
namespace: kube-system
#annotations:
# used to scrape app's metrics which deployed in pod  #  prometheus.io/scrape: 'true'
# prometheus scrape path, default /metrics
#  prometheus.io/path: '/metrics'
# prometheus.io/port relvant port
spec:
replicas: 1
selector:
matchLabels:
app: prometheus-server
template:
metadata:
labels:
app: prometheus-server
spec:
securityContext:
runAsUser: 0
containers:
- name: prometheus
image: prom/prometheus
args:
- "--config.file=/etc/l"            - "--storage.tsdb.path=/prometheus/"
ports:
- containerPort: 9090
protocol: TCP
volumeMounts:
- name: gluster-volume
mountPath: /prometheus
-
name: config-volume
mountPath: /etc/prometheus
serviceAccountName: prometheus
volumes:
- name: gluster-volume
emptyDir: {}
#persistentVolumeClaim:
nodeselector#  claimName: gluster-prometheus
- name: config-volume
configMap:
name: prometheus-server-conf
-
--
apiVersion: v1
kind: Service
metadata:
name: prometheus
namespace: kube-system
labels:
k8s-app: prometheus
spec:
selector:
app: prometheus-server
type: NodePort
ports:
- name: web
port: 9090
targetPort: 9090
4、deployment: kube-state-metrics
kind: Deployment
apiVersion: apps/v1
metadata:
name: kube-state-metrics
namespace: kube-system
selfLink: /apis/apps/v1/namespaces/kube-system/deployments/kube-state-metrics  uid: dc0e1a14-17a9-11e9-bbbc-fa163eb8f89d
resourceVersion: '10913395'
generation: 1
creationTimestamp: '2019-01-14T03:09:52Z'
labels:
grafanak8sapp: 'true'
k8s-app: kube-state-metrics
annotations:
deployment.kubernetes.io/revision: '1'
spec:
replicas: 1
selector:
matchLabels:
grafanak8sapp: 'true'
k8s-app: kube-state-metrics
template:
metadata:
creationTimestamp: null
labels:
grafanak8sapp: 'true'
k8s-app: kube-state-metrics
spec:
serviceAccountName: prometheus
containers:
- name: kube-state-metrics
image: 'quay.io/coreos/kube-state-metrics:v1.1.0'
ports:
- name: http-metrics
containerPort: 8080
protocol: TCP
resources: {}
readinessProbe:
httpGet:
path: /healthz
port: 8080
scheme: HTTP
initialDelaySeconds: 5
timeoutSeconds: 5
periodSeconds: 10
successThreshold: 1
failureThreshold: 3
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
imagePullPolicy: IfNotPresent
restartPolicy: Always
terminationGracePeriodSeconds: 30
dnsPolicy: ClusterFirst
securityContext: {}
schedulerName: default-scheduler
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 25%
maxSurge: 25%
revisionHistoryLimit: 2
progressDeadlineSeconds: 600

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。