gpt4 book ai didi

Kubernetes Ingress没有为grafana仪表板添加应用程序URL

转载 作者:行者123 更新时间:2023-12-04 07:16:17 24 4
gpt4 key购买 nike

我已经在我的Kubenernetes 1.9集群中安装了Grafan。当我使用入口URL(http://sample.com/grafana/)访问时获得第一页。使用该javascript之后,css下载不会将/grafana添加到URL。

这是我的入口规则:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: grafana-ingress-v1
namespace: monitoring
annotations:
ingress.kubernetes.io/rewrite-target: /
kubernetes.io/ingress.class: nginx
spec:
tls:
- hosts:
- sample.com
secretName: ngerss-tls
rules:
- host: sample.com
http:
paths:
- path: /grafana/
backend:
serviceName: grafana-grafana
servicePort: 80

在这里,我看到了关于同一主题的讨论。但这对我的问题无济于事。

https://github.com/kubernetes/contrib/issues/860
下图显示了第一个请求发送到/grafana/,但第二个请求未在URL中添加 /grafana/

enter image description here

最佳答案

您的入口规则是正确的,并且nginx创建了正确的虚拟主机以将流量转发到grafana的服务(我只留下了需要显示的字符串):

 server {
server_name sample.com;
listen 80;
listen [::]:80;
set $proxy_upstream_name "-";

location ~* ^/grafana/(?<baseuri>.*) {

set $proxy_upstream_name "default-grafana-grafana-80";

set $namespace "default";
set $ingress_name "grafana-ingress-v1";


rewrite /grafana/(.*) /$1 break;
rewrite /grafana/ / break;
proxy_pass http://default-grafana-grafana-80;

}

是的,当您转到 sample.com/grafana/时,您会收到来自grafana pod的响应,但它会重定向到 sample.com/login页面(您可以从提供的屏幕快照中看到此内容):
$ curl -v -L http://sample.com/grafana/
* Trying 192.168.99.100...
* Connected to sample.com (192.168.99.100) port 80 (#0)
> GET /grafana/ HTTP/1.1
> Host: sample.com
> User-Agent: curl/7.47.0
> Accept: */*
>
< HTTP/1.1 302 Found
< Server: nginx/1.13.5
< Date: Tue, 30 Jan 2018 21:55:21 GMT
< Content-Type: text/html; charset=utf-8
< Content-Length: 29
< Connection: keep-alive
< Location: /login
< Set-Cookie: grafana_sess=c07ab2399d82fef4; Path=/; HttpOnly
< Set-Cookie: redirect_to=%252F; Path=/
<
* Ignoring the response-body
* Connection #0 to host sample.com left intact
* Issue another request to this URL: 'http://sample.com/login'
* Found bundle for host sample.com: 0x563ff9bf7f20 [can pipeline]
* Re-using existing connection! (#0) with host sample.com
* Connected to sample.com (192.168.99.100) port 80 (#0)
> GET /login HTTP/1.1
> Host: sample.com
> User-Agent: curl/7.47.0
> Accept: */*
>
< HTTP/1.1 404 Not Found
< Server: nginx/1.13.5
< Date: Tue, 30 Jan 2018 21:55:21 GMT
< Content-Type: text/plain; charset=utf-8
< Content-Length: 21
< Connection: keep-alive
<
* Connection #0 to host sample.com left intact
default backend 404

因为默认情况下grafana的 root_url只是 /:
root_url = %(protocol)s://%(domain)s:%(http_port)s/

当请求仅重定向到 sample.com时,nginx将其转发到默认后端404。

解决方案:

您需要将 root_url grafana的服务器设置更改为 /grafana/:
root_url = %(protocol)s://%(domain)s:%(http_port)s/grafana/

您可以在grafana的 configmap对象中更改此设置。

关于Kubernetes Ingress没有为grafana仪表板添加应用程序URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48410293/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com