【发布时间】:2026-01-21 11:50:01
【问题描述】:
我已经使用helm 在我的Kubernetes 集群上安装了Prometheus 和Grafana:
$helm install prometheus prometheus-community/kube-prometheus-stack
所有pods、deployments 和services 都已启动并运行。当我像这样使用端口转发时:
kubectl port-forward deployment/prometheus-grafana 3000
我可以使用浏览器访问我的grafana dashboard,但是当我想使用ingress 而不是port-forward 时,响应是:
我无法访问 Grafana 仪表板。
我的ingress yaml 文件:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: grafana-ingress
namespace: default
spec:
ingressClassName: kong
rules:
- http:
paths:
- path: /grafana/login
pathType: Prefix
backend:
service:
name: prometheus-grafana
port:
number: 80
prometheus-grafana 服务 yaml 文件是:
# Please edit the object below. Lines beginning with a '#' will be ignored,
# and an empty file will abort the edit. If an error occurs while saving this file will be
# reopened with the relevant failures.
#
apiVersion: v1
kind: Service
metadata:
annotations:
meta.helm.sh/release-name: prometheus
meta.helm.sh/release-namespace: default
creationTimestamp: "2021-09-15T11:07:30Z"
labels:
app.kubernetes.io/instance: prometheus
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: grafana
app.kubernetes.io/version: 8.1.2
helm.sh/chart: grafana-6.16.4
name: prometheus-grafana
namespace: default
resourceVersion: "801373"
uid: e1f57de9-94d0-460a-a427-4a97fd770e12
spec:
clusterIP: 10.100.90.147
clusterIPs:
- 10.100.90.147
ports:
- name: service
port: 80
protocol: TCP
targetPort: 3000
selector:
app.kubernetes.io/instance: prometheus
app.kubernetes.io/name: grafana
sessionAffinity: None
type: ClusterIP
status:
loadBalancer: {}
【问题讨论】:
-
Ingress 中的路径 /grafana/login 对我来说有点奇怪。您不应该公开整个 /grafana 路径吗?也许登录页面试图将您重定向到另一个页面但不能,因为没有通往它的路线?
-
嗨@AndD!整个路径是什么意思?有点像 www.example.com/grafana/login ?
-
我的意思是,Ingress 只定义了一条路径,
/grafana/login,类型为Prefix。 Grafana 肯定会有除/grafana/login之外的其他路径,所以我首先尝试使用一条路径,/grafana。使用端口转发时,在哪个路径可以打开 grafana 仪表盘?因为 Grafana 可能会期望请求到达相同的路径。 -
当我使用端口转发时,我可以在
localhost:3000看到 grafana 仪表板 -
好的,这就解释了事情。 Grafana 是一个 Web 应用程序,希望直接在服务器的根路径下提供服务。您需要在
/下将其公开为路径,使用重写目标规则或在主机的子域下提供它。尝试使用路径/是否一切都按预期工作。
标签: kubernetes prometheus grafana