How can I configure Path for two services in Kubernetes Ingress?

3/9/2017

I've the following ingress configuration but when I call www.domain.com/api it always open my UI service instead of API and the same thing happens if I call something else after api, for example www.domain.com/api/v1/projects.

How can I fix that?

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress
spec:
  tls:
  - secretName: tls
  backend:
    serviceName: ui
    servicePort: 5003
  rules:
  - host: www.domain.com
    http:
      paths:
      - path: /
        backend:
          serviceName: ui
          servicePort: 5003
      - path: /api
        backend:
          serviceName: api
          servicePort: 5000
-- Celso Marques
google-cloud-platform
kubectl
kubernetes

1 Answer

3/10/2017

Here is the way I fixed this problem. I hope this can help others.

Thanks @aleks!!

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: kronus
spec:
  tls:
  - secretName: tls
  backend:
    serviceName: ui
    servicePort: 5003
  rules:
  - host: domain.com
    http:
      paths:
      - path: /api
        backend:
          serviceName: api
          servicePort: 5000
      - path: /api/*
        backend:
          serviceName: api
          servicePort: 5000
  - host: www.domain.com
    http:
      paths:
      - path: /api
        backend:
          serviceName: api
          servicePort: 5000
      - path: /api/*
        backend:
          serviceName: api
          servicePort: 5000
-- Celso Marques
Source: StackOverflow