apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-service
  annotations:
    # Tells k8s we want to make an ingress controller based on the nginx engine
    kubernetes.io/ingress.class: 'nginx'
    # Tells k8s to read paths using regex (means you have to write paths using regex!)
    nginx.ingress.kubernetes.io/use-regex: 'true'
    # Tells k8s we want to "remove" the /api routing we set up in our server so we don't need to have /api everywhere
    nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
  rules:
    - http:
        paths:
          # array below says any requests to / that are not /api will be routed to client
          - path: /?(.*)
            pathType: Prefix
            backend:
              service:
                name: client-cluster-ip-service
                port:
                  number: 3000
          # array below says any requests to /api/ will be routed to server
          - path: /api/?(.*)
            pathType: Prefix
            backend:
              service:
                name: server-cluster-ip-service
                port:
                  number: 5000