K8s Ingress rule for multiple paths in same backend service
To use multipath with the glbc ingress you need to have different services name such as the below example and each service (backend) has different path and one ingress can be configured (not two).
So , you don't need two ingress unless if you want to have two loadbalancer
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: fanout-ingress
spec:
rules:
- http:
paths:
- path: /*
backend:
serviceName: web
servicePort: 8080
- path: /v2/*
backend:
serviceName: web2
servicePort: 8080
There is Multi-Port Services, Kubernetes supports multiple port definitions on a Service object. When using multiple ports you must give all of your ports names. see below example
Here is answer using kubernetes ingress with nginx .
kind: Service
apiVersion: v1
metadata:
name: my-service
spec:
selector:
app: MyApp
ports:
- name: http
protocol: TCP
port: 80
targetPort: 9376
- name: https
protocol: TCP
port: 443
targetPort: 9377
Answering my question after learning more about ingress.
It wasn't an issue of wrong path forwarding to downstream. Basically gke ingress controller, expects a readiness probe to be present in backend. I was missing this in my deployment and because of it ingress was marking backend as "unknown"
Eventually reading other stackoverflow questions below on it helped me to solve the problem
gcp-load-balancer-backend-status-unknown
kubernetes-ingress-gce-keeps-returning-502-error
After introducing readiness probe as below, ingress was able to detect backend properly and passes on the request to backend.
apiVersion: apps/v1
kind: Deployment
metadata:
name: hello-app
labels:
app: hello-app
spec:
replicas: 1
selector:
matchLabels:
app: hello-app
template:
metadata:
labels:
app: hello-app
spec:
containers:
- name: hello-app
image: us.gcr.io/hello-app:latest
readinessProbe:
httpGet:
path: /healthz
port: 7799
periodSeconds: 1
timeoutSeconds: 1
successThreshold: 1
failureThreshold: 10