在之前的章节中,我们讲解了如何编写一个自定义的 Exporter,以便将指标暴露给 Prometheus 进行抓取。现在,我们将进一步扩展这个内容,介绍如何使用 prometheus-operator 在 Kubernetes 集群中自动发现并监控这些暴露的指标。
部署应用
在 Kubernetes 集群中部署我们的自定义上一章节中编写的 prometheus-go 应用。接下来需要下面的内容保存为 prometheus-go.yaml
文件,执行 kubectl apply -f prometheus-go.yaml
命令创建应用。
apiVersion: v1
kind: Service
metadata:
labels:
app: prometheus-go
name: prometheus-go-metrics
namespace: default
spec:
ports:
- name: http
port: 8080
protocol: TCP