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

Minikube中配置Kubernetes Ingress实现Angular与SpringBoot互联的正确性咨询

你的Ingress配置存在几个关键问题,修正后才能满足需求

当前配置的错误点:

  • Angular Ingress规则格式错误:你把host和http拆成了两个独立规则,正确写法是http作为host的子规则,需要缩进嵌套。
  • SpringBoot Ingress后端服务指向错误:你把后端指向了angular-service,这完全不对,应该改成你的SpringBoot服务名称(比如springboot-service)。
  • SpringBoot Ingress路径包含查询参数:Ingress的path只匹配URL的路径部分,不包含?后面的查询参数,Exact类型路径会因为带参数无法匹配,必须去掉参数,查询参数会自动透传给后端。
  • SpringBoot Ingress同样存在规则格式错误:和Angular的问题一致,host和http不能分成两个独立规则。

修正后的配置示例:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: angular-ingress
  namespace: default
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
    - host: angular.test
      http: # 缩进作为host的子项
        paths:
          - path: /
            pathType: Prefix  
            backend:
              service:
                name: angular-service
                port:
                  number: 8080
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: spring-ingress
  namespace: default
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
    - host: springboot.test
      http: # 缩进嵌套
        paths:
          - path: /exact/form-config/applicant/field
            pathType: Exact
            backend:
              service:
                name: springboot-service # 替换为你的SpringBoot服务名
                port:
                  number: 8080 # 替换为SpringBoot服务暴露的端口

让Angular用主机名连接后端的额外步骤:

  1. 获取Minikube的IP地址:执行minikube ip得到对应IP(比如192.168.49.2)
  2. 修改本地hosts文件(Windows路径:C:\Windows\System32\drivers\etc\hosts;Linux/macOS路径:/etc/hosts),添加两行:
    192.168.49.2 angular.test
    192.168.49.2 springboot.test
    
  3. 在Angular应用的配置里,把API请求地址设为http://springboot.test/exact/form-config/applicant/field,即可通过主机名访问后端服务。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.05 21:10:59