Skip to content

Commit 2788422

Browse files
Merge pull request #259 from marcel-dempers/H+hbohEh/iNPLT9P
Prometheus Operator updates
2 parents bff2467 + 22995cb commit 2788422

File tree

12 files changed

+1178
-0
lines changed

12 files changed

+1178
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: dotnet-application
5+
labels:
6+
app: dotnet-application
7+
spec:
8+
replicas: 1
9+
selector:
10+
matchLabels:
11+
app: dotnet-application
12+
template:
13+
metadata:
14+
labels:
15+
app: dotnet-application
16+
spec:
17+
containers:
18+
- name: dotnet-application
19+
image: dotnet-application:latest
20+
imagePullPolicy: IfNotPresent
21+
ports:
22+
- containerPort: 5000
23+
---
24+
apiVersion: v1
25+
kind: Service
26+
metadata:
27+
name: dotnet-application
28+
labels:
29+
app: dotnet-application
30+
spec:
31+
selector:
32+
app: dotnet-application
33+
ports:
34+
- port: 80
35+
name: http
36+
targetPort: 5000
37+
type: ClusterIP
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: go-application
5+
labels:
6+
app: go-application
7+
spec:
8+
replicas: 1
9+
selector:
10+
matchLabels:
11+
app: go-application
12+
template:
13+
metadata:
14+
labels:
15+
app: go-application
16+
spec:
17+
containers:
18+
- name: go-application
19+
image: go-application:latest
20+
imagePullPolicy: IfNotPresent
21+
ports:
22+
- containerPort: 5000
23+
---
24+
apiVersion: v1
25+
kind: Service
26+
metadata:
27+
name: go-application
28+
labels:
29+
app: go-application
30+
spec:
31+
selector:
32+
app: go-application
33+
ports:
34+
- port: 80
35+
targetPort: 5000
36+
name: http
37+
type: ClusterIP
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
# Kubernetes 1.33 Monitoring Guide
2+
3+
Create a cluster with [kind](https://kind.sigs.k8s.io/docs/user/quick-start/)
4+
5+
```
6+
cd monitoring\prometheus\kubernetes\1.33
7+
8+
kind create cluster --name monitoring --image kindest/node:v1.33.1 --config kind.yaml
9+
```
10+
11+
Test our cluster to see all nodes are healthy and ready:
12+
13+
```
14+
kubectl get nodes
15+
NAME STATUS ROLES AGE VERSION
16+
monitoring-control-plane Ready control-plane 110s v1.33.1
17+
monitoring-worker Ready <none> 98s v1.33.1
18+
monitoring-worker2 Ready <none> 98s v1.33.1
19+
monitoring-worker3 Ready <none> 98s v1.33.1
20+
```
21+
22+
# Kube Prometheus
23+
24+
The best method for monitoring, is to use the community project called `kube-prometheus`
25+
which you can find [here](https://github.com/prometheus-operator/kube-prometheus)
26+
27+
This project focusses on compiling manifests for a complete kubernetes monitoring solution, so with it comes the Prometheus Operator, Grafana, Prometheus instances with Service Monitors that scrape all the internal Kubernetes metrics so we can monitor pods, workloads, nodes and applications.
28+
29+
# Prometheus Community Helm Charts
30+
31+
To deploy this, the best method is to use the Prometheus community helm charts which you can find [here](https://github.com/prometheus-community/helm-charts)
32+
33+
```
34+
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
35+
helm search repo prometheus-community --versions
36+
```
37+
38+
Check the possible configuration options:
39+
40+
```
41+
helm show values prometheus-community/kube-prometheus-stack > prometheus-values.yaml
42+
```
43+
44+
## Configation
45+
46+
We can take anything from the values file and create our own `values.yaml` file to configure anything we want:
47+
48+
```
49+
```
50+
51+
## Installation
52+
53+
Firstly let's list the available chart versions
54+
55+
```
56+
helm search repo prometheus-community --versions > versions.log
57+
```
58+
59+
Let's proceed with installation:
60+
```
61+
CHART_VERSION=75.4.0
62+
helm install kube-prometheus-stack prometheus-community/kube-prometheus-stack \
63+
--version ${CHART_VERSION} \
64+
--namespace monitoring \
65+
--create-namespace \
66+
--values values.yaml
67+
```
68+
69+
## Prometheus Operator
70+
71+
72+
73+
# Check Monitoring
74+
75+
```
76+
kubectl -n monitoring get pods
77+
NAME READY STATUS RESTARTS AGE
78+
grafana-7d484fc668-x4bf9 2/3 Running 0 58s
79+
kube-state-metrics-7dd4c79774-cdk7k 1/1 Running 0 58s
80+
node-exporter-brkpr 1/1 Running 0 58s
81+
node-exporter-k9tpq 1/1 Running 0 58s
82+
node-exporter-m9bfj 1/1 Running 0 58s
83+
node-exporter-w7ct4 1/1 Running 0 58s
84+
prometheus-kube-prometheus-stack-prometheus-0 1/2 Running 0 45s
85+
prometheus-operator-c95dfdfb6-jrjwr 1/1 Running 0 58s
86+
```
87+
88+
To see how Prometheus is configured on what to scrape , we list service monitors
89+
90+
```
91+
kubectl -n monitoring get servicemonitors
92+
NAME AGE
93+
grafana 92s
94+
kube-prometheus-stack-apiserver 92s
95+
kube-prometheus-stack-coredns 92s
96+
kube-prometheus-stack-kube-controller-manager 92s
97+
kube-prometheus-stack-kube-etcd 92s
98+
kube-prometheus-stack-kube-proxy 92s
99+
kube-prometheus-stack-kube-scheduler 92s
100+
kube-prometheus-stack-kubelet 92s
101+
kube-prometheus-stack-prometheus 92s
102+
kube-state-metrics 92s
103+
node-exporter 92s
104+
prometheus-operator 92s
105+
```
106+
107+
Label selectors are used to map service monitor to kubernetes services. </br>
108+
That is how Prometheus is configured on what to scrape.
109+
110+
As an example you can describe a service monitor:
111+
112+
```
113+
kubectl -n monitoring describe servicemonitor node-exporter
114+
```
115+
116+
# View Dashboards
117+
118+
You can access the dashboards by using `port-forward` to access Grafana.
119+
It does not have a public endpoint for security reasons
120+
121+
```
122+
kubectl -n monitoring port-forward svc/grafana 3000:80
123+
```
124+
125+
Then access Grafana on [localhost:3000](http://localhost:3000/)
126+
127+
128+
## Check Prometheus
129+
130+
Similar to checking Grafana, we can also check Prometheus:
131+
132+
```
133+
kubectl -n monitoring port-forward svc/prometheus-operated 9090
134+
```
135+
136+
137+
138+
139+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
kind: Cluster
2+
apiVersion: kind.x-k8s.io/v1alpha4
3+
nodes:
4+
- role: control-plane
5+
- role: worker
6+
- role: worker
7+
- role: worker
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
nameOverride: ""
2+
alertmanager:
3+
enabled: false
4+
grafana:
5+
enabled: true
6+
fullnameOverride: "grafana"
7+
nodeSelector:
8+
kubernetes.io/os: linux
9+
adminPassword: admin
10+
prometheusOperator:
11+
fullnameOverride: "prometheus-operator"
12+
enabled: true
13+
nodeSelector:
14+
kubernetes.io/os: linux
15+
kube-state-metrics:
16+
fullnameOverride: "kube-state-metrics"
17+
nodeSelector:
18+
kubernetes.io/os: linux
19+
kubelet:
20+
serviceMonitor:
21+
enabled: true
22+
interval: "120s"
23+
prometheus:
24+
fullnameOverride: "prometheus"
25+
serviceAccount:
26+
create: true
27+
name: "prometheus-k8s"
28+
prometheusSpec:
29+
nodeSelector:
30+
kubernetes.io/os: linux
31+
retention: "30d"
32+
prometheus-node-exporter:
33+
fullnameOverride: "node-exporter"
34+
prometheus:
35+
monitor:
36+
enabled: true
37+
interval: "120s"
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Prometheus Operator
2+
3+
This walkthrough demonstrates the usage of the Prometheus Operator. </br>
4+
To follow this walkthrough , you will need [Kubernetes Monitoring](../1.33/README.md) in your cluster.
5+
6+
## Deploy applications to monitor
7+
8+
You may need to build the applications first using docker
9+
10+
```
11+
docker compose -f monitoring\prometheus\docker-compose.yaml build
12+
```
13+
14+
Load the images into our cluster created in the monitoring guide:
15+
16+
```
17+
kind load docker-image docker.io/library/go-application:latest --name monitoring
18+
kind load docker-image docker.io/library/dotnet-application:latest --name monitoring
19+
kind load docker-image docker.io/library/python-application:latest --name monitoring
20+
kind load docker-image docker.io/library/nodejs-application:latest --name monitoring
21+
```
22+
23+
Deploy our microservices:
24+
25+
```
26+
kubectl apply -f monitoring/prometheus/go-application/deployment.yaml
27+
kubectl apply -f monitoring/prometheus/dotnet-application/deployment.yaml
28+
kubectl apply -f monitoring/prometheus/python-application/deployment.yaml
29+
kubectl apply -f monitoring/prometheus/nodejs-application/deployment.yaml
30+
```
31+
32+
## Deploy a Prometheus Instance:
33+
34+
We will need a service account with RBAC permissions for our new Prometheus instances to access service monitors and allow scraping of service endpoints
35+
36+
```
37+
kubectl apply -f monitoring/prometheus/kubernetes/prometheus-operator/serviceaccount.yaml
38+
```
39+
40+
Apply Prometheus instance
41+
42+
```
43+
kubectl apply -f monitoring/prometheus/kubernetes/prometheus-operator/prometheus.yaml
44+
```
45+
46+
Apply Service Monitors
47+
48+
```
49+
kubectl apply -f monitoring/prometheus/kubernetes/prometheus-operator/servicemonitors.yaml
50+
```
51+
52+
We can now see our Prometheus instance in the `default` namespace:
53+
54+
```
55+
kubectl get pods
56+
NAME READY STATUS RESTARTS AGE
57+
dotnet-application-74dbc8b5d9-gmr7h 1/1 Running 0 14m
58+
go-application-65bbc698f-fjmqr 1/1 Running 0 14m
59+
nodejs-application-c47c5f4c8-b9hls 1/1 Running 0 14m
60+
prometheus-prometheus-applications-0 2/2 Running 0 33m
61+
python-application-759b44fff7-9q7ws 1/1 Running 0 14m
62+
```
63+
64+
Checkout the Prometheus instance
65+
66+
```
67+
kubectl port-forward prometheus-prometheus-applications-0 9090
68+
```
69+
70+
Checkout Grafana
71+
72+
```
73+
kubectl -n monitoring port-forward svc/grafana 3000:80
74+
```
75+
76+
Then access Grafana on [localhost:3000](http://localhost:3000/)
77+
78+
79+

0 commit comments

Comments
 (0)