将子路径设为我在 k3s 上的后端服务的 'root' 路径?
Making a sub-path the 'root' path of my backend services on k3s?
我有一个 k3s
集群,其中部署了 Prometheus 和 Alertmanager,并为它们每个设置了一个 Ingress
资源。我的初始设置分别是 prometheus.domain.com
和 alermanager.domain.com
,它们按预期工作。
不过,我想把它分别切换到domain.com/prometheus
和domain.com/alertmanager
,我研究过的选项都不行。
目标
让我的 Prometheus 服务工作,使 domain.com/prometheus
成为我的 Prometheus 路径的 'root',因此根据其默认行为自动重定向到 domain.com/prometheus/graph
,以及 Prometheus 下的所有子路径(警报、配置、管理API) 遵循相同的行为。
尝试 #1
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
app: Prometheus
annotations:
traefik.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- http:
paths:
- path: /prometheus($|/)(.*)
backend:
serviceName: prometheus
servicePort: 9090
通过 SSH 进入托管我的 k3s 集群的 Vagrant box:
$ kubectl get ingress
NAME CLASS HOSTS ADDRESS PORTS
prometheus <none> * 192.168.0.200 80
$ curl 192.168.0.200/prometheus
404 page not found
$ curl 192.168.0.200/prometheus/graph
404 page not found
尝试#2
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
app: Prometheus
annotations:
traefik.ingress.kubernetes.io/rule-type: PathPrefixStrip
spec:
rules:
- http:
paths:
- path: /prometheus
backend:
serviceName: prometheus
servicePort: 9090
与上面相同的结果。
您需要启动 prometheus:
--web.route-prefix="http://example.com/prometheus"
来自source code:
web.external-url",
"The URL under which Prometheus is externally reachable (for example, if Prometheus is served via a reverse proxy). Used for generating relative and absolute links back to Prometheus itself. If the URL has a path portion, it will be used to prefix all HTTP endpoints served by Prometheus. If omitted, relevant URL components will be derived automatically.
对于 altermanager,您需要设置:
--alertmanager.url=http://example.com/alertmanager
注意: 在这种情况下不要在入口中使用重写。
我有一个 k3s
集群,其中部署了 Prometheus 和 Alertmanager,并为它们每个设置了一个 Ingress
资源。我的初始设置分别是 prometheus.domain.com
和 alermanager.domain.com
,它们按预期工作。
不过,我想把它分别切换到domain.com/prometheus
和domain.com/alertmanager
,我研究过的选项都不行。
目标
让我的 Prometheus 服务工作,使 domain.com/prometheus
成为我的 Prometheus 路径的 'root',因此根据其默认行为自动重定向到 domain.com/prometheus/graph
,以及 Prometheus 下的所有子路径(警报、配置、管理API) 遵循相同的行为。
尝试 #1
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
app: Prometheus
annotations:
traefik.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- http:
paths:
- path: /prometheus($|/)(.*)
backend:
serviceName: prometheus
servicePort: 9090
通过 SSH 进入托管我的 k3s 集群的 Vagrant box:
$ kubectl get ingress
NAME CLASS HOSTS ADDRESS PORTS
prometheus <none> * 192.168.0.200 80
$ curl 192.168.0.200/prometheus
404 page not found
$ curl 192.168.0.200/prometheus/graph
404 page not found
尝试#2
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
app: Prometheus
annotations:
traefik.ingress.kubernetes.io/rule-type: PathPrefixStrip
spec:
rules:
- http:
paths:
- path: /prometheus
backend:
serviceName: prometheus
servicePort: 9090
与上面相同的结果。
您需要启动 prometheus:
--web.route-prefix="http://example.com/prometheus"
来自source code:
web.external-url", "The URL under which Prometheus is externally reachable (for example, if Prometheus is served via a reverse proxy). Used for generating relative and absolute links back to Prometheus itself. If the URL has a path portion, it will be used to prefix all HTTP endpoints served by Prometheus. If omitted, relevant URL components will be derived automatically.
对于 altermanager,您需要设置:
--alertmanager.url=http://example.com/alertmanager
注意: 在这种情况下不要在入口中使用重写。