Ingress-nginx: Can I define multiple paths for a service?

Created on 24 Jul 2018  路  7Comments  路  Source: kubernetes/ingress-nginx

Can I define multiple paths for a service? other path jump to the old service, /index.php/ads and /index.php/xcx_sendmsg jump to the new service `` . ThankYou

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: my-ingress
  namespace: my-ns
  annotations:
    kubernetes.io/ingress.class: "nginx"
spec:

  tls:
  - hosts:
    - my.cc
    secretName: my-cc-certs
  rules:
  - host: my.cc
    http:
      paths:
        # other path jump to the old service
      - path: '/index.php/ads' '/index.php/xcx_sendmsg'
        backend:
          serviceName: new-service
          servicePort: 8080
      # - path: /index.php/xcx_sendmsg #like above
      #   backend:
      #     serviceName: new-service
      #     servicePort: 8080

Most helpful comment

I wound up using annotation nginx.ingress.kubernetes.io/use-regex: "true" and then using regex at the path definition to avoid copy/pasta repetition for backend for each individual path. e.g.:

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: productpage-ingress
  annotations:
    nginx.ingress.kubernetes.io/use-regex: "true"
spec:
  rules:
  - host: books.minikube.local
    http:
      paths:
      - path: /(productpage|static|login|logout).*
        backend:
          serviceName: myservice
          servicePort: 9080

All 7 comments

@yangqinjiang you can do that repeating the sections.

i known that,but repeat is evil

i known that,but repeat is evil

Right, but that feature requires a change in the Ingress spec, something out of the scope of this project.

I was wondering the same thing and found this post. I have a feeling this will be a recurring subject.

is it working ??, i also want to use multiple path

Step:-1
Rather write multiple time,you can use like below in ingress file : (it is working for me)
rules:
- host: {{ .Values.ingress.host | quote }}
http:
paths:
{{- range .Values.backends }}
- path: "/movie-star-play/{{ .name }}/"
backend:
serviceName: {{ include "mvp-service.name" . }}
servicePort: http
{{- end }}
{{- end }}

Step:-2
then declare the "backends " in values file:
backends:

  • name: gvpm-consolidateds
    version: v0
  • name: gvpm-downfalls
    version: v0
  • name: gvpm-gvpcodes
    version: v0
  • name: gvpm-gvpproductservices
    version: v0
  • name: gvpm-rentals
    version: v0
  • name: gvpm-subscriptions
    version: v0
  • name: mov-netflixes
    version: v0
  • name: mov-preplans
    version: v0
  • name: mov-supercharges
    version: v0

I wound up using annotation nginx.ingress.kubernetes.io/use-regex: "true" and then using regex at the path definition to avoid copy/pasta repetition for backend for each individual path. e.g.:

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: productpage-ingress
  annotations:
    nginx.ingress.kubernetes.io/use-regex: "true"
spec:
  rules:
  - host: books.minikube.local
    http:
      paths:
      - path: /(productpage|static|login|logout).*
        backend:
          serviceName: myservice
          servicePort: 9080
Was this page helpful?
0 / 5 - 0 ratings

Related issues

smeruelo picture smeruelo  路  3Comments

yuyang0 picture yuyang0  路  3Comments

cabrinoob picture cabrinoob  路  3Comments

jwfang picture jwfang  路  3Comments

lachlancooper picture lachlancooper  路  3Comments