总目录索引:K8s从入门到放弃系列
1、部署dingtalk
apiVersion: apps/v1 kind: Deployment metadata: name: dingtalk namespace: prometheus spec: progressDeadlineSeconds: 600 replicas: 1 revisionHistoryLimit: 10 selector: matchLabels: app: dingtalk strategy: rollingUpdate: maxSurge: 25% maxUnavailable: 25% type: RollingUpdate template: metadata: labels: app: dingtalk spec: containers: image: timonwong/prometheus-webhook-dingtalk:latest imagePullPolicy: IfNotPresent args: - --ding.profile=webhook1=https://oapi.dingtalk.com/robot/send?access_token=xxxxxxxxx #自己钉钉token的地址 name: dingtalk ports: - containerPort: 8060 name: http protocol: TCP resources: limits: cpu: 50m memory: 100Mi requests: cpu: 50m memory: 100Mi securityContext: capabilities: {} terminationMessagePath: /dev/termination-log terminationMessagePolicy: File dnsPolicy: ClusterFirst restartPolicy: Always schedulerName: default-scheduler securityContext: {} terminationGracePeriodSeconds: 30 --- apiVersion: v1 kind: Service metadata: name: dingtalk namespace: prometheus spec: clusterIP: ports: - name: http port: 8060 protocol: TCP targetPort: 8060 selector: app: dingtalk sessionAffinity: None type: ClusterIP status: loadBalancer: {}
#https://github.com/timonwong/prometheus-webhook-dingtalk
2、命令行测试token是否能连通
curl 'https://oapi.dingtalk.com/robot/send?access_token=xxxxxxxxx' \
-H 'Content-Type: application/json' \
-d '{"msgtype": "text","text": {"content": "我就是我, 是不一样的烟火"}}'
能在钉钉群看到一下就说明成功了
3、在alertmanager中配置连接钉钉
apiVersion: v1 data: alertmanager.yml: | global: resolve_timeout: 5m route: group_by: [alertname] group_wait: 30s group_interval: 5m repeat_interval: 1h receiver: default routes: - receiver: default group_wait: 10s match_re: alertname: 内存使用率告警|磁盘使用率告警|CPU使用率告警 receivers: - name: 'default' webhook_configs: - url: 'http://dingtalk.prometheus.svc.cluster.local:8060/dingtalk/webhook1/send' send_resolved: true kind: ConfigMap metadata: labels: app: prometheus chart: prometheus-11.3.0 component: alertmanager heritage: Helm release: prometheus name: prometheus-alertmanager namespace: prometheus