Skip to content

Commit

Permalink
Add monitoring examples
Browse files Browse the repository at this point in the history
Update README
  • Loading branch information
slashpai committed Apr 20, 2022
1 parent 537ca69 commit e0a4477
Show file tree
Hide file tree
Showing 21 changed files with 295 additions and 0 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,15 @@
# prometheus-operator-examples

prometheus-operator example configs

## Pre-requisites

Create kind cluster or minikube cluster (examples in this repo are tested with minikube)

```bash
$ minikube delete && minikube start --kubernetes-version=v1.23.0 --memory=6g --bootstrapper=kubeadm --extra-config=kubelet.authentication-token-webhook=true --extra-config=kubelet.authorization-mode=Webhook --extra-config=scheduler.bind-address=0.0.0.0 --extra-config=controller-manager.bind-address=0.0.0.0
```

[kube-prometheus](https://github.com/prometheus-operator/kube-prometheus#quickstart) stack is configured in cluster before running any examples

**Note:** The configs in this repo should be treated as examples only. This is not tested in production cluster. These examples can serve as a starting point for creating production ready configs
18 changes: 18 additions & 0 deletions podmonitor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Pod Monitor

Monitor single or multiple pods

Look at manifest files in respective directories

- Create pod and pod monitors

```bash
kubectl apply -f ./single_pod
```

```bash
kubectl apply -f ./multiple_pods
```

- Refresh prometheus target page it should show pod monitor targets
![img](img/pod_monitor.png)
Binary file added podmonitor/img/pod_monitor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions podmonitor/multiple_pods/pod-monitor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: monitoring.coreos.com/v1
kind: PodMonitor
metadata:
name: multiple-pods-monitoring
namespace: default
labels:
app.kubernetes.io/name: multiple-pods-monitoring
spec:
selector:
matchLabels:
team: frontend
podMetricsEndpoints:
- port: web
- port: metric
15 changes: 15 additions & 0 deletions podmonitor/multiple_pods/pod-one.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: Pod
metadata:
name: pod-one
namespace: default
labels:
app.kubernetes.io/name: pod-one
team: frontend
spec:
containers:
- image: ghcr.io/rhobs/prometheus-example-app:0.4.1
name: prometheus-example-app
ports:
- name: web
containerPort: 8080
15 changes: 15 additions & 0 deletions podmonitor/multiple_pods/pod-two.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: Pod
metadata:
name: pod-two
namespace: default
labels:
app.kubernetes.io/name: pod-two
team: frontend
spec:
containers:
- image: ghcr.io/rhobs/prometheus-example-app:0.4.1
name: prometheus-example-app
ports:
- name: metric
containerPort: 8080
13 changes: 13 additions & 0 deletions podmonitor/single_pod/pod-monitor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: monitoring.coreos.com/v1
kind: PodMonitor
metadata:
name: single-instance-app
namespace: default
labels:
app.kubernetes.io/name: single-instance-app
spec:
selector:
matchLabels:
app.kubernetes.io/name: single-instance-app
podMetricsEndpoints:
- port: web
14 changes: 14 additions & 0 deletions podmonitor/single_pod/pod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: v1
kind: Pod
metadata:
name: single-instance-app
namespace: default
labels:
app.kubernetes.io/name: single-instance-app
spec:
containers:
- image: ghcr.io/rhobs/prometheus-example-app:0.4.1
name: prometheus-example-app
ports:
- name: web
containerPort: 8080
43 changes: 43 additions & 0 deletions probe/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Probe

- Probe can be used to describe blackbox checks. Inorder to work with probe, blackbox_exporter has to be deployed

- Monitor static targets or ingress

- Look at manifest files in respective directories

## Static Target Monitoring

- Create probe

```bash
kubectl apply -f ./static_target
```

- Refresh prometheus target page it should display probe ingress target

![img](img/probe_static_target.png)

## Ingress Monitoring

### Pre-requisites

- Deploy Ingress Controller

If using [minikube](https://kubernetes.io/docs/tasks/access-application-cluster/ingress-minikube/#enable-the-ingress-controller) simply enable ingress addon

```bash
minikube addons enable ingress
```

### Monitor Ingress Object

- Deploy app, create service, ingress and probe

```bash
kubectl apply -f ./ingress
```

- Refresh prometheus target page it should show probe ingress target

![img](img/probe_ingress.png)
Binary file added probe/img/probe_ingress.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added probe/img/probe_static_target.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions probe/ingress/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: example-app
namespace: default
labels:
app.kubernetes.io/name: example-app
spec:
replicas: 3
selector:
matchLabels:
app.kubernetes.io/name: example-app
template:
metadata:
labels:
app.kubernetes.io/name: example-app
spec:
containers:
- name: prometheus-example-app
image: ghcr.io/rhobs/prometheus-example-app:0.4.1
ports:
- name: web
containerPort: 8080
21 changes: 21 additions & 0 deletions probe/ingress/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: example-app-ingress
namespace: default
labels:
app.kubernetes.io/name: example-app
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
rules:
- host: example-app
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: web
port:
number: 8080
15 changes: 15 additions & 0 deletions probe/ingress/probe.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: monitoring.coreos.com/v1
kind: Probe
metadata:
name: probe-ingress
namespace: default
labels:
app.kubernetes.io/name: probe-ingress
spec:
prober:
url: blackbox-exporter.monitoring.svc:19115
targets:
ingress:
selector:
matchLabels:
app.kubernetes.io/name: example-app
13 changes: 13 additions & 0 deletions probe/ingress/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
kind: Service
apiVersion: v1
metadata:
name: example-app
namespace: default
labels:
app.kubernetes.io/name: example-app
spec:
selector:
app.kubernetes.io/name: example-app
ports:
- name: web
port: 8080
17 changes: 17 additions & 0 deletions probe/static_target/probe.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: monitoring.coreos.com/v1
kind: Probe
metadata:
name: probe-static-target
namespace: default
labels:
app.kubernetes.io/name: probe-static-target
spec:
prober:
url: blackbox-exporter.monitoring.svc:19115
targets:
staticConfig:
labels:
environment: prometheus.io
static:
- 'https://demo.do.prometheus.io'
- 'https://node.demo.do.prometheus.io'
12 changes: 12 additions & 0 deletions servicemonitor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Service Monitor

Monitor Kubernetes Services

- Deploy app, create service and service monitor

```bash
kubectl apply -f .
```

- Refresh prometheus target page it should show service monitor target
![img](img/service_monitor.png)
23 changes: 23 additions & 0 deletions servicemonitor/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: prometheus-example-app
namespace: default
labels:
app.kubernetes.io/name: prometheus-example-app
spec:
replicas: 3
selector:
matchLabels:
app.kubernetes.io/name: prometheus-example-app
template:
metadata:
labels:
app.kubernetes.io/name: prometheus-example-app
spec:
containers:
- name: prometheus-example-app
image: ghcr.io/rhobs/prometheus-example-app:0.4.1
ports:
- name: web
containerPort: 8080
Binary file added servicemonitor/img/service_monitor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions servicemonitor/service-monitor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: prometheus-example-app
namespace: default
labels:
app.kubernetes.io/name: prometheus-example-app
spec:
selector:
matchLabels:
app.kubernetes.io/name: prometheus-example-app
endpoints:
- port: web
13 changes: 13 additions & 0 deletions servicemonitor/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
kind: Service
apiVersion: v1
metadata:
name: prometheus-example-app
namespace: default
labels:
app.kubernetes.io/name: prometheus-example-app
spec:
selector:
app.kubernetes.io/name: prometheus-example-app
ports:
- name: web
port: 8080

0 comments on commit e0a4477

Please sign in to comment.