监控

监控 Ingress-Nginx

...
annotations:
   prometheus.io/port: "10254"
   prometheus.io/scrape: "true"
...

使用 ingress-nginx/deploy 安装的 Ingress-Nginx 已经内置了 /metrics 接口,并已启用,因此只需要在 Prometheus 的配置文件内添加 job 即可。

# 先将 Ingress-Nginx:10254 作为 Service
apiVersion: v1
kind: Service
metadata:
  # name 自己设定
  name: ingress-prome-svc
  namespace: ingress-nginx
spec:
  selector:
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
  ports:
  - name: export-port
    port: 10254
    targetPort: 10254

---
# 在 Prometheus 的 ConfigMap 中添加 Job
...
- job_name: 'ingress-nginx'
  static_configs:
  # 使用 FQDN
  # <svc-name>.<namespace>.svc.cluster.local
  - targets: ['ingress-prome-svc.ingress-nginx.svc.cluster.local:10254']

重载配置,使配置生效

浏览器访问 http://NodeIP:Port,查看。

使用 Exporter 监控应用

官方文档已分类总结 Exporter(包括第三方):EXPORTERS AND INTEGRATIONS

重载配置,使配置生效

浏览器访问 http://NodeIP:Port,查看。

监控集群节点

  • kube-state-metrics 主要关注的是业务相关的一些元数据,比如 Deployment、Pod、副本状态等

  • metrics-server 主要关注的是资源度量 API 的实现,比如 CPU、文件描述符、内存、请求延时等指标。

以上两种只是显示数据,并不提供数据存储服务。

服务发现

在 Kubernetes 下,Promethues 通过与 Kubernetes API 集成,目前主要支持5中服务发现模式,分别是:Node、Service、Pod、Endpoints、Ingress。

配置 ConfigMap

重载配置,使配置生效

浏览器访问 http://NodeIP:Port,查看。

[kubernetes_sd_config](https://prometheus.io/docs/prometheus/latest/configuration/configuration/#%3Ckubernetes_sd_config%3E)

Last updated

Was this helpful?