gpt4 book ai didi

kubernetes - K3s traefik入口返回网关超时

转载 作者:行者123 更新时间:2023-12-02 12:11:45 24 4
gpt4 key购买 nike

我目前正在玩一个基于rpi的k3s集群,并且观察到一个奇怪的现象。

我部署了两个应用程序。
第一个是nginx,我可以根据以下入口规则在url http://external-ip/foo上进行访问:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: foo
namespace: foo
annotations:
kubernetes.io/ingress.class: traefik
traefik.ingress.kubernetes.io/rule-type: "PathPrefixStrip"
traefik.ingress.kubernetes.io/rewrite-target: "/"
spec:
rules:
- http:
paths:
- path: /foo
backend:
serviceName: foo-service
servicePort: 8081

另一个是grafana,根据以下入口规则,我无法到达url http://external-ip/grafana:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: grafana
namespace: grafana
annotations:
kubernetes.io/ingress.class: traefik
traefik.ingress.kubernetes.io/rule-type: "PathPrefixStrip"
traefik.ingress.kubernetes.io/rewrite-target: "/"
spec:
rules:
- http:
paths:
- path: /grafana
backend:
serviceName: grafana-service
servicePort: 3000

当我直接在Pod上进行端口转发时,可以访问grafana应用程序,当我在grafana服务上使用端口转发时,它也可以工作。

但是,一旦我尝试通过子路径到达它,就会收到网关超时。

有人猜到我在想什么吗?

这里是grafana部署的部署和服务:
apiVersion: apps/v1
kind: Deployment
metadata:
name: grafana
namespace: grafana
labels:
app: grafana
tier: frontend
service: monitoring
spec:
selector:
matchLabels:
app: grafana
tier: frontend
template:
metadata:
labels:
app: grafana
tier: frontend
service: monitoring
spec:
containers:
- image: grafana
imagePullPolicy: IfNotPresent
name: grafana
envFrom:
- configMapRef:
name: grafana-config
ports:
- name: frontend
containerPort: 3000
protocol: TCP
---
apiVersion: v1
kind: Service
metadata:
name: grafana-service
namespace: grafana
labels:
app: grafana
tier: frontend
service: monitoring
spec:
selector:
app: grafana
tier: frontend
type: NodePort
ports:
- name: frontend
port: 3000
protocol: TCP
targetPort: 3000



我必须将以下两个参数添加到我的configmap中才能使其工作:
GF_SERVER_ROOT_URL=http://localhost:3000/grafana/   
GF_SERVER_FROM_SUB_PATH=true

最佳答案

正如我在评论中提到的,grafana不像默认的nginx那样监听/
有与此相关的github issue,如果要使其工作,应指定root_url

grafana.ini:
server:
root_url: https://subdomain.example.com/grafana
具体来看 thisthis注释。

@tehemaroo添加了自己的解决方案,其中包括更改configmap中的根url和sub_path

I had to add the following two parameters to my configmap to make it work:

GF_SERVER_ROOT_URL=http://localhost:3000/grafana/   
GF_SERVER_FROM_SUB_PATH=true
以及与此相关的 documentation

To serve Grafana behind a sub path:

Include the sub path at the end of the root_url.

Set serve_from_sub_path to true.

[server]
domain = example.com
root_url = %(protocol)s://%(domain)s:%(http_port)s/grafana/
serve_from_sub_path = true

关于kubernetes - K3s traefik入口返回网关超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62161489/

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