-
Notifications
You must be signed in to change notification settings - Fork 743
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
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 \ | ||
--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 | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.