问题描述
在我的kubernetes集群中,我想进行监视,所以我安装了grafana.
In my kubernetes cluster I would like to do monitoring so I installed grafana.
我想以http://example.com/monitoring
的形式访问grafana仪表板,因此我尝试将其包含在我的入口配置中
I would like to access the grafana dashboard as http://example.com/monitoring
, so I tried to include this in my ingress configuration
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: example-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
rules:
- host: example.com
http:
paths:
- path: /monitoring/(.*)
backend:
serviceName: grafana
servicePort: 80
想法是也要在其中添加其他路径,例如网站的/
.
The idea is to add other paths there as well, for example /
for the website.
我注意到Grafana将http://example.com/monitoring
重定向到http://example.com/login
.当然应该是http://example.com/monitoring/login
.解决此问题的首选方法是什么.可以用ingress
完成吗?还是我应该以某种方式告诉Grafana它在/monitoring
路径后面(如果可能)?
I noticed that Grafana redirects http://example.com/monitoring
to http://example.com/login
. Of course this should have been http://example.com/monitoring/login
. What would be the preferred way to fix this. Can it be done with ingress
or should I somehow tell Grafana that it is behind a /monitoring
path (if possible)?
我已经使用此.
更新:我已经按照以下建议修改了grafana图表的文件values.yaml
UPDATE: I've modified as suggested below the grafana chart's file values.yaml as follows
grafana.ini:
server:
domain: example.com
root_url: http://example.com/monitoring/
现在我得到了:
还有我用来安装grafana的heml命令:
And the heml command I use to install grafana:
$> helm install stable/grafana -f values.yaml --set persistence.enabled=true --set persistence.accessModes={ReadWriteOnce} --set persistence.size=8Gi -n grafana
推荐答案
这是HTTP反向代理背后的服务的常见问题.幸运的是,Grafana提供了一种让它知道它在后面运行的上下文路径的方法.
This is a common problem with services that are behind an HTTP reverse-proxy. Luckily, Grafana offers a way to let it know the context path it is running behind.
在grafana.ini
(最有可能通过ConfigMap提供给其Kubernetes部署)中,您需要指定如下变量:
In grafana.ini
(which is most possibly supplied via a ConfigMap to its Kubernetes deployment), you need to specify the variables like the following:
[server]
domain = example.com
root_url = http://example.com/monitoring/
在此处查看完整文档: https://grafana.com/docs/installation/behind_proxy/
See the full documentation here: https://grafana.com/docs/installation/behind_proxy/
这篇关于尝试使用Ingress重写Grafana的url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!