How do you set up ingress for a Kubernetes cluster in Rancher?

5/19/2020

I am following the steps from the Rancher quick start guide and I am useing 2 VMs:

  • VM #1: I am running the Rancher server (in a Docker container) and a Rancher agent with 3 roles: etcd, control plane and worker
  • VM #2: a Rancher agent with a worker

I am trying to set up an ingress that will route to a simple Java REST API to a simple nodeJS app - each of these needs to have a path.

This is the ingress definition that we are trying to satisfy:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress
  annotations:
    kubernetes.io/ingress.class: nginx
spec:
  rules:
    - http:
        paths:
          - path: /
            backend:
              serviceName: front-end
              servicePort: 3000
          - path: /supermarket/
            backend:
              serviceName: backend
              servicePort: 8081

This is ingress definition is working with the GKE.

When I apply it to Rancher, it tells us that we have 2 IP addresses - 1 for VM #1 and another for VM #2. When we open the IP of VM #1, we get served the Rancher UI, but when we open the IP of VM #2, we get a connection timeout - as if there is no port open there. So it appears that none of them is serving the ingress.

What is the correct IP that we need to use to hit the ingress? For example, I want to be able to open http:///supermarket/ and get a response from the backend.

-- Borislav T
kubernetes-ingress
rancher

1 Answer

5/20/2020

Do you have any other ingress objects in the same namespace? If you do, I would suggest you specify host in your ingress object as below:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress
  annotations:
    kubernetes.io/ingress.class: nginx
spec:
  rules:
    - host: foo.bar.com
      http:
        paths:
          - path: /
            backend:
              serviceName: front-end
              servicePort: 3000
          - path: /supermarket
            backend:
              serviceName: backend
              servicePort: 8081

Once you apply this manifest, you will be able to access your backend on http://foo.bar.com/supermarket and your front-end on http://foo.bar.com/

-- hdhruna
Source: StackOverflow