Ingress controller nginx kubernetes not working

10/16/2019

I facing a problem in an ingress controller nginx kubernetes that is deployed in minikube : when i included the route that nginx will use to redirect the request it didn't work , however when i remove the route it work : So , as is explained in yaml file when i use /category it didn't work , however with with just / it is working

---- load balancer ---
    apiVersion: extensions/v1beta1
    kind: Ingress
    metadata:
      name: spare-ingress-dev
      namespace: default
      annotations:
        kubernetes.io/ingress.class: nginx
        nginx.ingress.kubernetes.io/rewrite-target: /
    spec:
      rules:
         - http:
            paths:
              - path: /
                backend:
                  serviceName: cluster-test-ip
                  servicePort: 80
              - path: /category/
                backend:
                  serviceName: cluster-category-ip
                  servicePort: 5200

----service-----

    apiVersion: v1
    kind: Service
    metadata:
      name: cluster-category-ip
    spec:
      selector:
        app: category
      ports:
        - port: 5200
          targetPort: 5200
-- Mehdi Gasserini
kubernetes

2 Answers

10/16/2019

Can you try this -

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: spare-ingress-dev
  namespace: default
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/rewrite-target: $1
spec:
  rules:
     - http:
        paths:
          - path: /(.*)
            backend:
              serviceName: cluster-test-ip
              servicePort: 80
          - path: /category/(.*)
            backend:
              serviceName: cluster-category-ip
              servicePort: 5200
-- Tushar Mahajan
Source: StackOverflow

10/17/2019
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: spare-ingress-dev
  namespace: default
  annotations:
     kubernetes.io/ingress.class: nginx
     nginx.ingress.kubernetes.io/use-regex: "true"
     nginx.ingress.kubernetes.io/app-root: /
spec:
 rules:
  - host: cluster.io
    http:
       paths:
        - path: /api/v1.0/auth/(.+)
          backend:
            serviceName: cluster-auth-ip
            servicePort: 6000
        - path: /api/v1.0/category/(.+)
          backend:
            serviceName: cluster-category-ip
            servicePort: 5200
        - path: /category/(.+)
          backend:
            serviceName: cluster-category-ip
            servicePort: 5200

i found the solution i removed nginx.ingress.kubernetes.io/rewrite-target: $1 and i added

kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/use-regex: "true"
nginx.ingress.kubernetes.io/app-root: /
-- Mehdi Gasserini
Source: StackOverflow