Use Kubernetes Ingress to have path routing with IP (no host/domainname) in GCP

11/26/2019

I have no access to create a DNS/Domainname and therefore I am not able to fill the host field in my ingress' YAML file.

I simply want to use the IP like this:

10.10.10.10/foo

10.10.10.10/bar

This is my ingress' YAML file:

 apiVersion: extensions/v1beta1
    kind: Ingress
    metadata:
        name: foobar-ingress
        annotations:
            kubernetes.io/ingress.global-static-ip-name: foobar-trigger-static-ip
    spec:
        rules:
             http:
                  paths:
                      - path: /foo/*
                        backend:
                            serviceName: foo
                            servicePort: 80
                      - path: /bar/*
                        backend:
                            serviceName: bar
                            servicePort: 80

This is not valid as I try to push it with Helm. I was not able to find any information to that in https://kubernetes.io/docs/concepts/services-networking/ingress/ since all the YAML examples are using a host. Is this even possible to do? Or is a host mandatory for that?

EDIT: I am using the GCP LoadBalancer

-- xetra11
kubernetes
kubernetes-ingress

1 Answer

11/26/2019

You can specify nginx class in annotation to rewrite the incoming requests as below

apiVersion: extensions/v1beta1
    kind: Ingress
    metadata:
        name: foobar-ingress
        annotations:
          kubernetes.io/ingress.global-static-ip-name: foobar-trigger-static-ip
          kubernetes.io/ingress.class: nginx
          nginx.ingress.kubernetes.io/rewrite-target: /$1
    spec:
        rules:
             http:
                  paths:
                      - path: /foo/?(.*)
                        backend:
                            serviceName: foo
                            servicePort: 80
                      - path: /bar/?(.*)
                        backend:
                            serviceName: bar
                            servicePort: 80
-- akshay
Source: StackOverflow