Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert nginx configuration to ingress kubernetes yaml configuration?

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
like image 485
Fauzan Avatar asked May 13 '19 07:05

Fauzan


1 Answers

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: |
      try_files $uri $uri/ /index.html; 
...
like image 190
Crou Avatar answered Oct 06 '22 02:10

Crou