3

I've Prometheus operator which is working as expected https://github.com/coreos/prometheus-operator

Now I want to apply the alert manager from scratch

After reading the docs im came out with those yamls. but the problem is when I entered to the UI Nothing is shown, any idea what I miss here ?

http://localhost:9090/alerts I use port forwarding ...

This is all the config files I've apply to my k8s cluster I just want to do some simple test to see that it working and then extend it to our needs...

alertmanger_main.yml

---
apiVersion: monitoring.coreos.com/v1
kind: Alertmanager
metadata:
  name: main
  labels:
    alertmanager: main
spec:
  replicas: 3
  version: v0.14.0

alertmanger_service.yml

apiVersion: v1
kind: Service
metadata:
  name: alertmanager-main
spec:
  type: LoadBalancer
  ports:
  - name: web
    port: 9093
    protocol: TCP
    targetPort: web
  selector:
    alertmanager: main

testalert.yml

kind: ConfigMap
apiVersion: v1
metadata:
  name: prometheus-example-rules
  labels:
    role: prometheus-rulefiles
    prometheus: prometheus
data:
  example.rules.yaml: |+
    groups:
    - name: ./example.rules
      rules:
      - alert: ExampleAlert
        expr: vector(1)

alertmanager.yml

global:
  resolve_timeout: 5m
route:
  group_by: ['job']
  group_wait: 30s
  group_interval: 5m
  repeat_interval: 12h
  receiver: 'webhook'
receivers:
- name: 'webhook'
  webhook_configs:
  - url: 'http://alertmanagerwh:30500/'

and to create secret I use

kubectl create secret generic alertmanager-main --from-file=alertmanager.yaml

what I need is some basic alerts in K8S and I follow the documatation but didnt find any good step by step tutorial

enter image description here

to check my sys for monitoring namespace

 ~  kubectl get pods -n monitoring                                                                                                                                                13.4m  Sun Feb 17 18:48:16 2019
NAME                                  READY   STATUS    RESTARTS   AGE
kube-state-metrics-593czc6b4-mrtkb   2/2     Running   0          12h
monitoring-grafana-771155cbbb-scqvx   1/1     Running   0          12h
prometheus-operator-79f345dc67-nw5zc   1/1     Running   0          12h
prometheus-prometheus-0               3/3     Running   1          12h
 ~  kubectl get svc -n  monitoring                                                                                                                                                536ms  Sun Feb 17 21:04:51 2019
NAME                   TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
alertmanager-main   NodePort    100.22.170.666   <none>        9093:30904/TCP   4m53s
kube-state-metrics     ClusterIP   100.34.212.596   <none>        8080/TCP         4d7h
monitoring-grafana     ClusterIP   100.67.230.884   <none>        80/TCP           4d7h
prometheus-operated    ClusterIP   None             <none>        9090/TCP         4d7h

I've also now changed the service to LoadBalancer and I try to enter like

 ~  kubectl get svc -n  monitoring                                                                                                                                                507ms  Sun Feb 17 21:23:56 2019
NAME                   TYPE           CLUSTER-IP       EXTERNAL-IP      PORT(S)          AGE
alertmanager-main   LoadBalancer   100.22.170.666   38.482.152.331   9093:30904/TCP   23m

when I hit the browser with

38.482.152.331:9093 
38.482.152.331:30904 

nothing happen...

4

1 回答 1

3

当您考虑使用AlertManager时,除了常规配置和应用警报规则外,还AlertManager需要与Prometheus服务器集成。然后,Prometheus 实例可以跟踪任何传入的一系列事件,一旦检测到任何被识别的规则,它就会向嵌套的警报管理器触发警报。

为了启用警报,可能需要将以下配置附加到 Prometheus 实例:

alerting:
  alertmanagers:
  - static_configs:
    - targets:
      - 'alertmanagerIP:9093'

具体来说,AlertManagerCoreOS中的实现,可以按照官方Alerting文档中描述的步骤进行;但是,您可以在下面找到上述指南中保留的 Prometheus pod 警报配置示例:

apiVersion: monitoring.coreos.com/v1
kind: Prometheus
metadata:
  name: example
spec:
  replicas: 2
  alerting:
    alertmanagers:
    - namespace: default
      name: alertmanager-example
      port: web
  serviceMonitorSelector:
    matchLabels:
      team: frontend
  resources:
    requests:
      memory: 400Mi
  ruleSelector:
    matchLabels:
      role: prometheus-rulefiles
      prometheus: example
于 2019-02-19T11:18:30.893 回答