Skip to content

Commit c8f0732

Browse files
committed
prom
1 parent f29f706 commit c8f0732

15 files changed

+668
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
groups:
2+
- name: kube-state-metrics
3+
rules:
4+
- alert: KubeStateMetricsListErrors
5+
annotations:
6+
message: kube-state-metrics is experiencing errors at an elevated rate in list
7+
operations. This is likely causing it to not be able to expose metrics about
8+
Kubernetes objects correctly or at all.
9+
expr: |
10+
(sum(rate(kube_state_metrics_list_total{job="kube-state-metrics",result="error"}[5m]))
11+
/
12+
sum(rate(kube_state_metrics_list_total{job="kube-state-metrics"}[5m])))
13+
> 0.01
14+
for: 15m
15+
labels:
16+
severity: critical
17+
- alert: KubeStateMetricsWatchErrors
18+
annotations:
19+
message: kube-state-metrics is experiencing errors at an elevated rate in watch
20+
operations. This is likely causing it to not be able to expose metrics about
21+
Kubernetes objects correctly or at all.
22+
expr: |
23+
(sum(rate(kube_state_metrics_watch_total{job="kube-state-metrics",result="error"}[5m]))
24+
/
25+
sum(rate(kube_state_metrics_watch_total{job="kube-state-metrics"}[5m])))
26+
> 0.01
27+
for: 15m
28+
labels:
29+
severity: critical
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
3+
kubectl -n kube-system delete service/kube-state-metrics
4+
kubectl -n kube-system delete deployment.apps/kube-state-metrics
5+
kubectl -n kube-system delete serviceaccount/kube-state-metrics
6+
kubectl delete clusterrolebinding.rbac.authorization.k8s.io/kube-state-metrics
7+
kubectl delete clusterrole.rbac.authorization.k8s.io/kube-state-metrics
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
apiVersion: rbac.authorization.k8s.io/v1
2+
kind: ClusterRoleBinding
3+
metadata:
4+
labels:
5+
app.kubernetes.io/name: kube-state-metrics
6+
app.kubernetes.io/version: v1.9.2
7+
name: kube-state-metrics
8+
roleRef:
9+
apiGroup: rbac.authorization.k8s.io
10+
kind: ClusterRole
11+
name: kube-state-metrics
12+
subjects:
13+
- kind: ServiceAccount
14+
name: kube-state-metrics
15+
namespace: kube-system
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
apiVersion: rbac.authorization.k8s.io/v1
2+
kind: ClusterRole
3+
metadata:
4+
labels:
5+
app.kubernetes.io/name: kube-state-metrics
6+
app.kubernetes.io/version: v1.9.2
7+
name: kube-state-metrics
8+
rules:
9+
- apiGroups:
10+
- ""
11+
resources:
12+
- configmaps
13+
- secrets
14+
- nodes
15+
- pods
16+
- services
17+
- resourcequotas
18+
- replicationcontrollers
19+
- limitranges
20+
- persistentvolumeclaims
21+
- persistentvolumes
22+
- namespaces
23+
- endpoints
24+
verbs:
25+
- list
26+
- watch
27+
- apiGroups:
28+
- extensions
29+
resources:
30+
- daemonsets
31+
- deployments
32+
- replicasets
33+
- ingresses
34+
verbs:
35+
- list
36+
- watch
37+
- apiGroups:
38+
- apps
39+
resources:
40+
- statefulsets
41+
- daemonsets
42+
- deployments
43+
- replicasets
44+
verbs:
45+
- list
46+
- watch
47+
- apiGroups:
48+
- batch
49+
resources:
50+
- cronjobs
51+
- jobs
52+
verbs:
53+
- list
54+
- watch
55+
- apiGroups:
56+
- autoscaling
57+
resources:
58+
- horizontalpodautoscalers
59+
verbs:
60+
- list
61+
- watch
62+
- apiGroups:
63+
- authentication.k8s.io
64+
resources:
65+
- tokenreviews
66+
verbs:
67+
- create
68+
- apiGroups:
69+
- authorization.k8s.io
70+
resources:
71+
- subjectaccessreviews
72+
verbs:
73+
- create
74+
- apiGroups:
75+
- policy
76+
resources:
77+
- poddisruptionbudgets
78+
verbs:
79+
- list
80+
- watch
81+
- apiGroups:
82+
- certificates.k8s.io
83+
resources:
84+
- certificatesigningrequests
85+
verbs:
86+
- list
87+
- watch
88+
- apiGroups:
89+
- storage.k8s.io
90+
resources:
91+
- storageclasses
92+
- volumeattachments
93+
verbs:
94+
- list
95+
- watch
96+
- apiGroups:
97+
- admissionregistration.k8s.io
98+
resources:
99+
- mutatingwebhookconfigurations
100+
- validatingwebhookconfigurations
101+
verbs:
102+
- list
103+
- watch
104+
- apiGroups:
105+
- networking.k8s.io
106+
resources:
107+
- networkpolicies
108+
verbs:
109+
- list
110+
- watch
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
labels:
5+
app.kubernetes.io/name: kube-state-metrics
6+
app.kubernetes.io/version: v1.9.2
7+
name: kube-state-metrics
8+
namespace: kube-system
9+
spec:
10+
replicas: 1
11+
selector:
12+
matchLabels:
13+
app.kubernetes.io/name: kube-state-metrics
14+
template:
15+
metadata:
16+
labels:
17+
app.kubernetes.io/name: kube-state-metrics
18+
app.kubernetes.io/version: v1.9.2
19+
spec:
20+
containers:
21+
- image: quay.io/coreos/kube-state-metrics:v1.9.2
22+
livenessProbe:
23+
httpGet:
24+
path: /healthz
25+
port: 8080
26+
initialDelaySeconds: 5
27+
timeoutSeconds: 5
28+
name: kube-state-metrics
29+
ports:
30+
- containerPort: 8080
31+
name: http-metrics
32+
- containerPort: 8081
33+
name: telemetry
34+
readinessProbe:
35+
httpGet:
36+
path: /
37+
port: 8081
38+
initialDelaySeconds: 5
39+
timeoutSeconds: 5
40+
nodeSelector:
41+
kubernetes.io/os: linux
42+
serviceAccountName: kube-state-metrics
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
apiVersion: v1
2+
kind: ServiceAccount
3+
metadata:
4+
labels:
5+
app.kubernetes.io/name: kube-state-metrics
6+
app.kubernetes.io/version: v1.9.2
7+
name: kube-state-metrics
8+
namespace: kube-system
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
labels:
5+
app.kubernetes.io/name: kube-state-metrics
6+
app.kubernetes.io/version: v1.9.2
7+
name: kube-state-metrics
8+
namespace: kube-system
9+
spec:
10+
clusterIP: None
11+
ports:
12+
- name: http-metrics
13+
port: 8080
14+
targetPort: http-metrics
15+
- name: telemetry
16+
port: 8081
17+
targetPort: telemetry
18+
selector:
19+
app.kubernetes.io/name: kube-state-metrics
Binary file not shown.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
apiVersion: v1
2+
kind: Namespace
3+
metadata:
4+
name: monitoring
5+
labels:
6+
type: monitoring
7+
8+
---
9+
10+
apiVersion: apps/v1
11+
kind: Deployment
12+
metadata:
13+
name: grafana
14+
labels:
15+
app: grafana-ui
16+
namespace: monitoring
17+
spec:
18+
replicas: 1
19+
selector:
20+
matchLabels:
21+
app: grafana-ui
22+
template:
23+
metadata:
24+
name: grafana
25+
labels:
26+
app: grafana-ui
27+
spec:
28+
containers:
29+
- name: grafana
30+
image: lerndevops/grafana
31+
ports:
32+
- containerPort: 3000
33+
34+
---
35+
apiVersion: v1
36+
kind: Service
37+
metadata:
38+
name: grafana-ui-svc
39+
labels:
40+
app: grafana-ui
41+
namespace: monitoring
42+
spec:
43+
type: NodePort
44+
selector:
45+
app: grafana-ui
46+
ports:
47+
- port: 3000
48+
protocol: TCP
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
apiVersion: v1
2+
kind: Namespace
3+
metadata:
4+
name: monitoring
5+
labels:
6+
type: monitoring
7+
---
8+
9+
apiVersion: v1
10+
kind: ConfigMap
11+
metadata:
12+
name: prom-server-conf
13+
labels:
14+
name: prom-server-conf
15+
namespace: monitoring
16+
data:
17+
prometheus.yml: |-
18+
global:
19+
scrape_interval: 15s # By default, scrape targets every 15 seconds.
20+
21+
# Attach these labels to any time series or alerts when communicating with
22+
# external systems (federation, remote storage, Alertmanager).
23+
external_labels:
24+
monitor: 'codelab-monitor'
25+
# A scrape configuration containing exactly one endpoint to scrape:
26+
# Here it's Prometheus itself.
27+
scrape_configs:
28+
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
29+
- job_name: 'prometheus'
30+
# Override the global default and scrape targets from this job every 5 seconds.
31+
scrape_interval: 5s
32+
static_configs:
33+
- targets: ['localhost:9090']
34+
35+
---
36+
37+
apiVersion: apps/v1
38+
kind: Deployment
39+
metadata:
40+
name: prom-deployment
41+
labels:
42+
app: prometheus
43+
namespace: monitoring
44+
spec:
45+
replicas: 2
46+
selector:
47+
matchLabels:
48+
app: prometheus
49+
template:
50+
metadata:
51+
labels:
52+
app: prometheus
53+
spec:
54+
containers:
55+
- name: prometheus
56+
image: prom/prometheus
57+
volumeMounts:
58+
- name: config-volume
59+
mountPath: /etc/prometheus/prometheus.yml
60+
subPath: prometheus.yml
61+
ports:
62+
- containerPort: 9090
63+
volumes:
64+
- name: config-volume
65+
configMap:
66+
name: prom-server-conf
67+
68+
---
69+
70+
kind: Service
71+
apiVersion: v1
72+
metadata:
73+
name: prom-svc
74+
namespace: monitoring
75+
spec:
76+
type: NodePort
77+
selector:
78+
app: prometheus
79+
ports:
80+
- name: promui
81+
protocol: TCP
82+
port: 9090
83+
targetPort: 9090

0 commit comments

Comments
 (0)