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

AKS跨命名空间部署Ingress暴露服务的配置调整咨询

问题分析与修正方案

你遇到的Ingress部署失败问题,主要来自跨命名空间Service访问限制、YAML配置错误以及路由规则不匹配这几个方面,以下是具体修改步骤和修正后的配置:

一、解决跨命名空间Service访问问题

Kubernetes Ingress默认只能引用同一命名空间下的Service,因此需要在wallarm-ingress命名空间创建一个代理Service,指向ingress-basic里的api Service:

# 在wallarm-ingress命名空间创建此Service
apiVersion: v1
kind: Service
metadata:
  name: api-proxy
  namespace: wallarm-ingress
spec:
  type: ExternalName
  externalName: api.ingress-basic.svc.cluster.local
  ports:
  - port: 3333

二、修正Ingress配置

原Ingress存在语法错误、无效配置和路由规则问题,修正后的完整配置如下:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: hello-world-ingress
  annotations:
    nginx.ingress.kubernetes.io/ssl-redirect: "false"
    nginx.ingress.kubernetes.io/use-regex: "true"
    nginx.ingress.kubernetes.io/rewrite-target: /$1
  namespace: wallarm-ingress

spec:
  ingressClassName: nginx
  rules:
  - http:
      paths:
      - path: /one(/|$)(.*)
        pathType: ImplementationSpecific
        backend:
          service:
            name: api-proxy
            port:
              number: 3333
      - path: /(.*)
        pathType: ImplementationSpecific
        backend:
          service:
            name: api-proxy
            port:
              number: 3333

三、关键修改点说明

  • 修正命名空间:将Ingress的metadata.namespace改为wallarm-ingress,匹配你的部署计划。
  • 删除无效配置:移除annotations里的name: api,这不属于Ingress的合法注解。
  • 移除重复配置:删除kubernetes.io/ingress.class注解,K8s 1.19+版本推荐使用spec.ingressClassName。
  • 调整路由pathType:正则匹配的path建议使用ImplementationSpecific,而非Prefix,避免路由匹配冲突。
  • 修正rewrite规则:第二个path/(.*)只有一个捕获组,因此rewrite-target改为/$1,避免路由解析错误。
  • 引用代理Service:Ingress指向wallarm-ingress下的api-proxy Service,绕开跨命名空间访问限制。

四、部署验证

  1. 创建代理Service:
kubectl apply -f api-proxy.yaml -n wallarm-ingress
  1. 部署修正后的Ingress:
kubectl apply -f ingress.yaml -n wallarm-ingress
  1. 查看Ingress状态:
kubectl get ingress hello-world-ingress -n wallarm-ingress
  1. 测试访问:
curl http://<Ingress公网IP>/one/test
curl http://<Ingress公网IP>/test

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.09 06:25:17