Locust UI静态文件404导致页面渲染异常求助
问题解决:Locust UI通过Ingress访问时静态文件404
核心原因分析
端口转发正常但Ingress访问静态文件返回404,说明Ingress的请求转发规则未正确将/static路径的请求传递给Locust服务,或是Locust服务的端口映射在Ingress配置中存在偏差。
解决方案
1. 确认Ingress转发端口指向Locust Web端口
deliveryhero的Locust Helm Chart中,Leader节点的Web服务默认端口为8089,需确保Ingress正确关联Service的该端口:
- 先通过命令检查Service配置:
确认存在kubectl get svc locust -n testing -o yaml8089端口的暴露配置:spec: ports: - name: web port: 8089 targetPort: 8089 - 在Helm的Ingress配置中明确指定转发端口:
ingress: enabled: true # 保留原有annotations配置... hosts: - host: locust.test.mywebsite.com pathType: Prefix path: / servicePort: 8089 # 明确指向Locust的Web服务端口
2. 修改Ingress的PathType为Prefix
当前配置的pathType: ImplementationSpecific可能导致ALB的路径匹配逻辑不符合预期,改为Prefix可确保所有以/开头的请求(包括/static/*)都被转发到Locust服务:
ingress: hosts: - host: locust.test.mywebsite.com pathType: Prefix path: /
3. 补充/static路径的Ingress规则(可选)
若上述调整无效,可添加单独的Ingress规则专门处理静态文件请求:
ingress: hosts: - host: locust.test.mywebsite.com pathType: Prefix path: / - host: locust.test.mywebsite.com pathType: Prefix path: /static/ servicePort: 8089
4. 验证ALB目标组的路径转发配置
登录AWS控制台检查ALB对应的目标组,确认未设置路径重写或过滤规则,确保所有请求路径(含/static/*)完整转发到Locust容器的8089端口。
5. 验证Locust容器的静态文件服务
若怀疑Locust服务本身的问题,可通过端口转发进入容器测试:
kubectl exec -it <locust-leader-pod-name> -n testing -- curl http://localhost:8089/static/jquery.tools.min.js
若返回正常的JS内容,说明Locust服务本身无问题,问题仍出在Ingress/ALB的转发配置上。
验证操作
修改配置后执行Helm升级:
helm upgrade locust deliveryhero/locust -n testing -f your-values.yaml
等待Ingress和ALB配置更新完成后,重新访问https://locust.test.mywebsite.com,检查静态文件是否加载正常。
内容的提问来源于stack exchange,提问作者user2295803
相关产品推荐
相关产品推荐

