How to convert nginx configuration to ingress kubernetes yaml configuration?

5/13/2019

I deployed Vue JS on kubernetes. And I need to configure nginx route like on this page :

https://router.vuejs.org/guide/essentials/history-mode.html#example-server-configurations

The configuration is like this :

location / {
  try_files $uri $uri/ /index.html;
} 

How to convert that configuration to ingress kubernetes yaml configuration?

I tried this but doesn't work

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /index.html
  name: backoffice
  namespace: default
  selfLink: /apis/extensions/v1beta1/namespaces/default/ingresses/backoffice
spec:
  rules:
    - host: dev.abc.com
      http:
        paths:
          - backend:
              serviceName: backoffice-svc
              servicePort: 443
            path: /

And I tried with this annotation and still doesn't work :

nginx.ingress.kubernetes.io/app-root: /app1
-- Fauzan
kubernetes-ingress
nginx
nginx-ingress
url-rewriting

1 Answer

5/13/2019

The Ingress might look like the following:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: some-nice-server
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/ssl-redirect: "false"
    nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
  rules:
  - host: "some.nice.server.com"
    http:
      paths:
      - path: /something1/?(.*)
        backend:
          serviceName: something-1
          servicePort: 8080

This is nicely explained in Kubernetes Ingress-Nginx dosc.

Or, you might also use Configuration snippet in Annotations:

...
nginx.ingress.kubernetes.io/configuration-snippet: |
    location / {
      try_files $uri $uri/ /index.html;
    } 
...
-- Crou
Source: StackOverflow