You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

K3s集群中Traefik Ingress访问InfluxDB仅显示空白页求助

问题分析与解决方案

核心问题

通过Ingress子路径/influxdb访问时页面空白,本质是两个关键问题:

  • Traefik路径重写规则配置错误,导致请求未正确转发到InfluxDB的根路径
  • InfluxDB未配置子路径前缀,其返回页面的静态资源(JS/CSS)仍使用根路径,浏览器无法加载

具体修复步骤

1. 修正Ingress的路径重写配置

Traefik v2+不再使用旧的rewrite-target注释,需通过自定义中间件实现路径重写。先创建Traefik中间件:

apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
  name: influxdb-path-rewrite
  namespace: monitoring
spec:
  replacePathRegex:
    regex: ^/influxdb(.*)
    replacement: /$1

更新Ingress配置,关联该中间件:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: tig-ingress
  namespace: monitoring
  annotations:
    traefik.ingress.kubernetes.io/router.middlewares: monitoring-influxdb-path-rewrite@kubernetescrd
spec:
  ingressClassName: traefik
  rules:
  - host: test.example.local
    http:
      paths:
      - path: /influxdb
        pathType: Prefix
        backend:
          service:
            name: influxdb-service
            port:
              number: 8086
      - path: /grafana
        pathType: Prefix
        backend:
          service:
            name: grafana-service
            port:
              number: 3000

2. 配置InfluxDB的子路径前缀

修改InfluxDB的Deployment,添加环境变量指定运行的子路径,确保静态资源路径正确:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: influxdb-deployment
  namespace: monitoring
spec:
  replicas: 1
  selector:
    matchLabels:
      app: influxdb
  template:
    metadata:
      labels:
        app: influxdb
    spec:
      containers:
      - name: influxdb
        image: influxdb:latest
        ports:
        - containerPort: 8086
        volumeMounts:
        - name: influxdb-storage
          mountPath: /var/lib/influxdb
        envFrom:
        - secretRef:
            name: influxdb-secrets
        env:
        - name: INFLUXD_HTTP_PREFIX
          value: "/influxdb"
        - name: INFLUXD_HTTP_LOG_ENABLED
          value: "true"
      volumes:
      - name: influxdb-storage
        persistentVolumeClaim:
          claimName: influxdb-pvc

3. 应用配置并验证

执行命令更新资源:

kubectl apply -f middleware.yaml -n monitoring
kubectl apply -f updated-ingress.yaml -n monitoring
kubectl rollout restart deployment/influxdb-deployment -n monitoring

等待Pod重启完成后,访问http://test.example.local/influxdb即可正常显示登录页面。

补充说明

  • Grafana需同步配置:添加对应路径重写中间件,并在Deployment中设置GF_SERVER_ROOT_URL=http://test.example.local/grafana环境变量,避免出现相同的空白页面问题
  • 确保本地DNS已将test.example.local解析到K3s集群的Traefik入口节点IP

内容的提问来源于stack exchange,提问作者HochWieBreit

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.29 07:47:22