设置 nginx-ingress 以将两条路径匹配到相同的 serviceName 和 servicePort

Setup nginx-ingress to match two paths to the same serviceName and servicePort

我想做什么

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress-service
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/add-base-url: "true"
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
    - http:
        paths:
          - path: /?(.*)
            backend:
              serviceName: client-cluster-ip-service
              servicePort: 3000
          - path: /api?/(.*)
            backend:
              serviceName: server-cluster-ip-service
              servicePort: 5000

问题

# urls.py
urlpatterns = [
    path('auth/', include('authentication.urls')),
    path('admin/', admin.site.urls),
]

什么有效

- path: /?(.*)
  backend:
    serviceName: server-cluster-ip-service
    servicePort: 5000

不知何故,我需要防止 Django 剥离前缀。或者也许有一种方法可以处理来自 nginx-ingress.

的这种类型的路由

什么不起作用

以下任何变体:

- http:
    paths:
      - path: /?(.*)
        backend:
          serviceName: client-cluster-ip-service
          servicePort: 3000
      - path: /api?/(.*)
        backend:
          serviceName: server-cluster-ip-service
          servicePort: 5000
      - path: /admin?/(.*)
        backend:
          serviceName: server-cluster-ip-service
          servicePort: 5000

urlpatterns = [
    path('auth/', include('authentication.urls')),
    path('/', admin.site.urls),
]

urlpatterns = [
    path('auth/', include('authentication.urls')),
    path('', admin.site.urls),
]

urlpatterns = [
    path('auth/', include('authentication.urls')),
    path('api/admin/', admin.site.urls), # this justmakes it /api/api/admin given the ingress
]

# This just makes the URL pattern:
# - /api/api/auth/
# - /api/api/admin/
urlpatterns = [
    path('api/', include([
        path('auth/', include('authentication.urls'), name='auth'),
        path('admin/', admin.site.urls),
    ])),
]

问题

所以不太确定如何解决这个问题。

向 Django settings.py 添加了以下内容:

 FORCE_SCRIPT_NAME = '/api/'

更新 STATIC_URL 因为它将不再为管理门户提供资产:

 STATIC_URL = '/api/static/`