Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Add prometheus-operator tutorial #524

Merged
merged 4 commits into from
Mar 27, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
144 changes: 144 additions & 0 deletions docs/gitbook/tutorials/prometheus-operator.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
# Flagger with Prometheus Operator

This guide will show you how to use Flagger and Prometheus Operator
This guide will handle only Blue/Green Deployment

## Prerequisites

Flagger requires a Kubernetes cluster **v1.11** or newer and NGINX ingress **0.24** or newer.

Install Prometheus-Operator with Helm v3:

```bash
helm repo add stable https://kubernetes-charts.storage.googleapis.com
helm repo update
kubectl create ns prometheus
helm upgrade -i prometheus stable/prometheus-operator \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use fullnameOverride and set the namespace to monitoring so that the URL will look better.

--namespace prometheus \
--set prometheus.prometheusSpec.serviceMonitorSelectorNilUsesHelmValue=false
```
The `prometheus.prometheusSpec.serviceMonitorSelectorNilUsesHelmValue` allows Prometheus-Operator to watch serviceMonitor outside of his namespace.

Install Flagger with Helm v3:

```bash
helm repo add flagger https://flagger.app
helm repo update
kubectl create ns flagger
helm upgrade -i flagger flagger/flagger \
--namespace flagger
--set prometheus-prometheus-oper-prometheus.prometheus:9090 \
stefanprodan marked this conversation as resolved.
Show resolved Hide resolved
--set meshProvider=kubernetes
```

The `meshProvider` option can be changed to your value

## Setting ServiceMonitor

Prometheus Operator is using mostly serviceMonitor instead of annotations.
In order to catch metrics for primary and canary service, you will need to create 2 serviceMonitors :

```yaml
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: service-monitor-primary
namespace: application
spec:
endpoints:
- path: /metrics
port: http
selector:
matchLabels:
app: application
```

```yaml
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: service-monitor-canary
namespace: application
spec:
endpoints:
- path: /metrics
port: http
selector:
matchLabels:
app: application-canary
```

## Setting Custom metrics

Prometheus Operator is relabeling for every serviceMonitor, you can create custom metrics

```yaml
apiVersion: flagger.app/v1beta1
kind: MetricTemplate
metadata:
name: your-custom-metrics
namespace: application
spec:
provider:
address: http://prometheus-prometheus-oper-prometheus.prometheus:9090
type: prometheus
query: |
100 - sum(
rate(
http_server_requests_seconds_max{
namespace="{{namespace }}",
job="{{ target }}-canary",
status!~\"5.*\"
}[{{ interval }}]
)
)
/
sum(
rate(
http_server_requests_seconds_max{
namespace="{{ namespace }}",
job="{{ target }}-canary"
}[{{ interval }}]
)
)
* 100
```

You can use the job to filter instead of pod. You can tune it to your installation.

## Creating Canary

```yaml
apiVersion: flagger.app/v1beta1
kind: Canary
metadata:
name: application
namespace: security-manager
spec:
analysis:
interval: 30s
iterations: 10
threshold: 5
metrics:
- interval: 1m
name: http-requests-seconds
templateRef:
name: your-custom-metrics
namespace: application
thresholdRange:
max: 1
webhooks: []
progressDeadlineSeconds: 600
provider: kubernetes
service:
port: 8080
portDiscovery: true
targetRef:
apiVersion: v1
kind: Deployment
name: application
```

You can define the webhooks of your liking also