返回社区案例

排查 Prometheus Ingress 访问不通的问题

发布时间:2026/6/26浏览量:408

【最近实战】

最近在 Kubernetes 集群中部署了 Prometheus,配置了 Ingress 域名 prometheus.marcpoint.com,但访问一直不通。而同一个 namespace 下的 Grafana Ingress(graf.marcpoint.com)却能正常访问。我通过 Wisdom SSH 连接到服务器,让 AI 助手帮我排查这个问题。

我首先查看了 Ingress 列表,发现 Grafana 的 Ingress 有 ADDRESS 显示为 ***,而 Prometheus 的 ADDRESS 列为空:

kubectl get ingress -n monitor
NAME                 CLASS    HOSTS                      ADDRESS       PORTS   AGE
grafana-ingress      <none>   graf.marcpoint.com         ***          80      3d13h
prometheus-ingress   <none>   prometheus.marcpoint.com                 80      51s

ADDRESS 为空说明 Ingress 没有被 Ingress Controller 接管。我让 AI 助手对比两个 Ingress 的完整 YAML 配置,找出差异。

AI 助手分别导出了两个 Ingress 的配置。Grafana 的 Ingress 关键部分:

metadata:
  annotations:
    kubernetes.io/ingress.class: nginx
spec:
  rules:
  - host: graf.marcpoint.com
    http:
      paths:
      - backend:
          service:
            name: grafana-service
            port:
              number: 3000
        path: /
        pathType: Prefix
status:
  loadBalancer:
    ingress:
    - ip: ***

Prometheus 的 Ingress 关键部分:

metadata:
  annotations: {}
spec:
  rules:
  - host: prometheus.marcpoint.com
    http:
      paths:
      - backend:
          service:
            name: prometheus-service
            port:
              number: 9090
        path: /
        pathType: Prefix
status:
  loadBalancer: {}

问题一目了然:Prometheus 的 Ingress 缺少 kubernetes.io/ingress.class: nginx 这个注解。在 Kubernetes 中,Ingress 资源需要指定 ingress.class 注解来告诉集群使用哪个 Ingress Controller 来处理这个 Ingress 规则。Grafana 的 Ingress 有这个注解,所以 Nginx Ingress Controller 接管了它并分配了 ADDRESS;Prometheus 没有这个注解,Controller 直接忽略了它,导致 ADDRESS 为空,域名自然无法访问。

AI 助手直接在 prometheus-deployment.yaml 的 Ingress 部分添加了这个注解。修改前:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: prometheus-ingress
  namespace: monitor
spec:

修改后:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: nginx
  name: prometheus-ingress
  namespace: monitor
spec:

这个问题的根因是在编写 Prometheus 部署 YAML 时漏掉了 ingress.class 注解。在同一个集群中,如果 Grafana 的 Ingress 已经通过注解指定了 nginx 作为 Ingress Controller,那么新增的 Prometheus Ingress 也必须加上同样的注解,否则 Controller 不会处理它。这是 Kubernetes Ingress 的一个常见坑:不同 Ingress Controller 通过 ingress.class 来区分自己负责的 Ingress 资源,不加注解等于没有指定 Controller。

通过 Wisdom SSH 的 AI 辅助,我快速定位了配置差异并完成了修复,整个过程从发现问题到解决只用了不到一分钟。

本文由用户分享,展示了Wisdom SSH在AI运维中的实际应用

推荐社区案例

点击阅读真实AI运维案例