[英]K3s traefik ingress returns gateway timeout
I am currently playing around with a rpi based k3s cluster and I am observing a weird phenomenon.我目前正在使用基于 rpi 的 k3s 集群,我正在观察一个奇怪的现象。
I deployed two applications.我部署了两个应用程序。 The first one is nginx which I can reach on the url http://external-ip/foo based on the following ingress rule:
第一个是 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
And the other one is grafana which I cannot reach on the url http://external-ip/grafana based on the below ingress rule:另一个是 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
When I do a port-forward directly on the pod I can reach the grafana app, when I use the port-forward on the grafana service it also works.当我直接在 pod 上进行端口转发时,我可以访问 grafana 应用程序,当我在 grafana 服务上使用端口转发时,它也可以工作。
However as soon as I try to reach it through the subpath I will get a gateway timeout.但是,一旦我尝试通过子路径到达它,我就会得到网关超时。
Does anyone have a guess what I am missing?有人猜我错过了什么吗?
Here the deployment and service for the grafana deployment:这里是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
I had to add the following two parameters to my configmap to make it work:我必须将以下两个参数添加到我的 configmap 以使其工作:
GF_SERVER_ROOT_URL=http://localhost:3000/grafana/
GF_SERVER_FROM_SUB_PATH=true
As I mentioned in comments grafana is not listening on /
like default nginx.正如我在评论中提到的那样,grafana 没有听
/
喜欢默认的 nginx。
There is related github issue about this, and if you want to make it work you should specify root_url有相关的github 问题,如果你想让它工作,你应该指定 root_url
grafana.ini:
server:
root_url: https://subdomain.example.com/grafana
Specifically take a look at this and this comment.具体看看这个和这个评论。
@tehemaroo add his own solution which include changing root url and sub_path in configmap @tehemaroo 添加他自己的解决方案,包括在 configmap 中更改 root url 和 sub_path
I had to add the following two parameters to my configmap to make it work:
我必须将以下两个参数添加到我的 configmap 以使其工作:
GF_SERVER_ROOT_URL=http://localhost:3000/grafana/
GF_SERVER_FROM_SUB_PATH=true
And related documentation about that以及有关的相关文档
To serve Grafana behind a sub path:
在子路径后面服务 Grafana:
Include the sub path at the end of the root_url.
在 root_url 的末尾包含子路径。
Set serve_from_sub_path to true.
将 serve_from_sub_path 设置为 true。
[server]
domain = example.com
root_url = %(protocol)s://%(domain)s:%(http_port)s/grafana/
serve_from_sub_path = true
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.