Creating a path based Ingress on a GKE cluster

1/4/2020

So I am in the process of migrating my bare metal cluster onto GKE and ran into an issue with the ingress. On my bare metal cluster, I used the ingress controller from nginxinc which worked fine. Below is a sample of an Ingress file of a particular deployment:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
namespace: mynamespace
name: app-ingress
annotations: 
    kubernetes.io/ingress.class: "nginx"
    nginx.ingress.kubernetes.io/ssl-redirect: "false"
    nginx.ingress.kubernetes.io/rewrite-target: /$2
spec:
rules:
- host: myhost
    http:
    paths:
    - path: /dev/appname(/|$)(.*)
        backend:
          serviceName: app
          servicePort: 80

Basically, when a user types in myhost/dev/appname, myhost is resolved to a HAProxy server. The proxy then routes the request to the NodePort that the ingress service is running on.

I tried to do the same thing on my GKE cluster with the only exception being that the Ingress controller on the GKE cluster is exposed using a LoadBalancer as per the documentation

However I get a 502 error if I try to access the URL.

TL;DR: Looking for the best way to access various applications (deployments) deployed on a GKE cluster using URL's like: myhost/dev/firstapp and myhost/dev/secondapp etc.

-- user538578964
google-kubernetes-engine
kubernetes
nginx-ingress

2 Answers

1/5/2020

You can use Kong Ingress as your ingress controller on GKE for your path based ingresses. You can install Kong Ingress from GCP Marketplace. It is easy to integrate and also supports various plugins for authenticating, monitoring etc.

You'll get detailed information and installation instructions from https://github.com/Kong/google-marketplace-kong-app#basic-usage

-- Shahed Mehbub
Source: StackOverflow

1/5/2020

I would follow this guide on setting up Nginx on GKE. The ingress looks like below:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress-resource
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/ssl-redirect: "false"
spec:
  rules:
  - http:
      paths:
      - path: /hello
        backend:
          serviceName: hello-app
          servicePort: 8080 

You should be able to access your app externally http://external-ip-of-ingress-controller/hello

Now to debug 502 issue verify that the health-checks from the Loadbalancer to your app is passing or not.

-- Arghya Sadhu
Source: StackOverflow