01hanst
01hanst

Reputation: 597

kubernetes ingress path must end with / to be recognized

I'm deploying this list.

  1. Front gist
  2. Back gist
  3. MySQL gist
  4. PhpMyAdmin gist
  5. Ingress gist

And Ingress NodePort is 80:31361, 443:30482 in kubectl get svc -n ingress-nginx

The problem is in Ingress.

To load PhpMyAdmin page, I typed url as http://my-ip:31361/pma.

But every resources are not found with 404 error.

If I typed url as http://my-ip:31361/pma/, It works finely.

Only difference is /.

Why this is happen?

How can I page pma or main without /?

Upvotes: 0

Views: 935

Answers (1)

01hanst
01hanst

Reputation: 597

apiVersion: networking.k8s.io/v1

kind: Ingress 
metadata:   
  name: ingress   
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/rewrite-target: /$2
    nginx.ingress.kubernetes.io/configuration-snippet: |
      rewrite ^\/(main|pma)$ $1/ permanent; 
spec:   
  rules:
    - http:
      paths:
      - path: /main(/|$)(.*)
        pathType: Prefix
        backend:
          service:
            name: frontend-service
            port:
              number: 80
      - path: /pma(/|$)(.*)
        pathType: Prefix
        backend:
          service:
            name: pma-service
            port:
              number: 80

As a result, I didn't remove /.

However, If user load page as /main, nginx will redirect to /main/, /pma -> /pma/.

Then every resouces are accessible.

Thank you @P....

Upvotes: 1

Related Questions