Kubernetes Ingress - Pass only sub path to backend and not full path

9/29/2021

I want a Ingress, that routes host.com/abc/xyz to service/xyz. I have the following configuration but its routing host.com/abc/xyz to service/abc/xyz.

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    appgw.ingress.kubernetes.io/connection-draining: "true"
    appgw.ingress.kubernetes.io/connection-draining-timeout: "30"
    appgw.ingress.kubernetes.io/request-timeout: "300"
    appgw.ingress.kubernetes.io/health-probe-status-codes: "200-399, 401"
    kubernetes.io/ingress.class: azure/application-gateway
  generation: 1
  name: serviceAingress
  namespace: pantry-services
spec:
  rules:
  - host: myhost.net
    http:
      paths:
      - backend:
          serviceName: serviceA
          servicePort: 8083
        path: /abc/*
        pathType: Prefix
      - backend:
          serviceName: serviceA
          servicePort: 8083
        path: /abc
        pathType: Prefix

How can I route myhost.net/abc/ to service/ ? the abc should not be included in the backend call. I've tried pathType as ImplementationSpecific too

-- Jerald Baker
azure-application-gateway
kubernetes
kubernetes-ingress

2 Answers

1/19/2022
-- Jerald Baker
Source: StackOverflow

10/5/2021

If your service is a host name. Name-based virtual hosts support routing HTTP traffic to multiple host names at the same IP address. Would Suggest you to please use the below. yaml code

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: name-virtual-host-ingress
spec:
  rules:
  - host: myhost.net
    http:
      paths:
      - pathType: Prefix
        path: "abc/*"
        backend:
          service:
            name: service1
            port:
              number: 80
  - host: service
    http:
      paths:
      - pathType: Prefix
        path: "/*"
        backend:
          service:
            name: service2
            port:
              number: 80

If you create an Ingress resource without any hosts defined in the rules, then any web traffic to the IP address of your Ingress controller can be matched without a name based virtual host being required.

For example, the following Ingress routes traffic requested for myhost.net/abc/ to service1, service/* to service2

Reference: https://kubernetes.io/docs/concepts/services-networking/ingress/

-- RahulKumarShaw-MT
Source: StackOverflow