Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kubernetes ingress setting up multiple hosts

I've set up two simple kubernetes services & deployments - frontend & api. The frontend gets data from the api so I'm exposing the api as well so I can hard code the backend ingress URL in the frontend data fetch call (if anyone knows a better way of doing this internally within cluster please let me know).

I'm trying to set up different host names for different services but for some reason only one of the hostnames is working.

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: test-webapp-ingress
  annotations:
    ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - host: test-webapp-frontend.com
    http:
      paths:
        - path: /
          backend:
            serviceName: test-webapp-frontend-lb
            servicePort: 8002
  - host: test-webapp-api.com
    http:
      paths:
        - path: /get
          backend:
            serviceName: test-webapp-api-lb
            servicePort: 8001

And this is what I get after I run kubectl get svc

NAME                      TYPE           CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
kubernetes                ClusterIP      10.96.0.1        <none>        443/TCP          2d
test-webapp-api-lb        LoadBalancer   10.107.60.163    <pending>     8001:30886/TCP   1h
test-webapp-frontend-lb   LoadBalancer   10.104.100.108   <pending>     8002:31431/TCP   1h

I am using minikube on my local to run this cluster. I can access both the frontend and api by running minikube service test-webapp-frontend-lb and minikube service test-webapp-api-lb.

When I go to test-webapp-frontend.com, I can see the frontend page but I can't access test-webapp-api.com. Not even the default not-found error, I just can't access it as if the URL just didn't exist.

The weird thing is, if I do this,

spec:
  rules:
  - host: test-webapp-frontend.com
    http:
      paths:
        - path: /
          backend:
            serviceName: test-webapp-frontend-lb
            servicePort: 8002
  - host: test-another-frontend.com
    http:
      paths:
        - path: /
          backend:
            serviceName: test-webapp-frontend-lb
            servicePort: 8002

I can still access test-webapp-frontend.com but test-another-frontend.com has the same problem, can't access it at all.

What am I doing wrong??

like image 238
mkim Avatar asked Oct 14 '18 15:10

mkim


People also ask

How do I have multiple controllers in Kubernetes ingress?

First, ensure the --controller-class= and --ingress-class are set to something different on each ingress controller, If your additional ingress controller is to be installed in a namespace, where there is/are one/more-than-one ingress-nginx-controller(s) already installed, then you need to specify a different unique -- ...

Can Kubernetes have multiple ingress?

8.0, one can install multiple NGINX ingress controllers in a Kubernetes cluster. The optional NGINX Ingress Controller can be installed as an App on your cluster.

Can I have multiple ingress resources?

Based on the concept of a controller, there is only one GKE Ingress controller in a cluster, which is responsible for fulfilling multiple resources and provisioning multiple load balancers.


1 Answers

Seems like a DNS problem. Those hostname a like 'test-webapp-frontend.com' need to resolve to the IP of the ingress controller to route traffic into the cluster. I don't see an external IP listed in your output for an ingress controller. For minikube you could enable the ingress add-on. DNS is a bit trickier with minikube as you don't have a public IP to resolve to. You can modify you etc/hosts file to resolve the names or use path-based rules instead.

Some useful links on this

like image 112
Ryan Dawson Avatar answered Oct 08 '22 23:10

Ryan Dawson