Kubernetes Ingress on multiple paths with custom host results in 404

9/22/2019

I'm new to Ingress. I followed the offical site to build simple fanout of Ingress with multiple paths for same custom host. However, it returns 404. I cannot figure out what is problem on my configurations.
I have enabled ingress in minikube & add <minikube ip> localhost-log.com into /etc/hosts

Here are my some configuration YAMLs:

deployment.yaml

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: kibana
spec:
  selector:
    matchLabels:
      run: kibana
  template:
    metadata:
      labels:
        run: kibana
    spec:
      containers:
      - name: kibana
        image: docker.elastic.co/kibana/kibana:6.5.4
        env:
        - name: ELASTICSEARCH_URL
          value: http://elasticsearch:9200
        - name: XPACK_SECURITY_ENABLED
          value: "true"
        ports:
        - containerPort: 5601
          name: http
          protocol: TCP

service.yaml

apiVersion: v1
kind: Service
metadata:
  name: kibana
  labels:
    service: kibana
spec:
  type: NodePort
  selector:
    run: kibana
  ports:
  - port: 80
    targetPort: 5601
    nodePort: 32561

ingress.yaml

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress-test
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - host: localhost-log.com
    http:
      paths:
      - path: /logger
        backend:
          serviceName: logger-svc
          servicePort: 80
      - path: /kibana
        backend:
          serviceName: kibana
          servicePort: 80

If query kibana service using kubectl port-forward, it is able to get to kibana website.

port forward -> <minikube ip>:nodePort -> success

But if I use ingress, for example, http://localhost-log.com/kibana, instead of directly querying services, it fails & return default backend - 404.

The verbose output of ingress: kubectl describe ingress ingress-test -n=logging

Name:             ingress-test
Namespace:        logging
Address:          10.0.2.15
Default backend:  default-http-backend:80 (172.17.0.9:8080)
Rules:
  Host               Path  Backends
  ----               ----  --------
  localhost-log.com  
                     /logger   logger-svc:80 (172.17.0.4:30080)
                     /kibana   kibana:80 (172.17.0.7:5601)
Annotations:
  kubectl.kubernetes.io/last-applied-configuration:  {
  "apiVersion": "extensions/v1beta1",
  "kind": "Ingress",
  "metadata": {
    "annotations": {
      "nginx.ingress.kubernetes.io/rewrite-target": "/"
    },
    "name": "ingress-test",
    "namespace": "logging"
  },
  "spec": {
    "rules": [
      {
        "host": "localhost-log.com",
        "http": {
          "paths": [
            {
              "backend": {
                "serviceName": "logger-svc",
                "servicePort": 80
              },
              "path": "/logger"
            },
            {
              "backend": {
                "serviceName": "kibana",
                "servicePort": 80
              },
              "path": "/kibana"
            }
          ]
        }
      }
    ]
  }
}

What I want or from my understanding, I would like http://localhost-log.com/kibana => <kibana>:80, but it seems not correct. It redirect to http://localhost-log.com/app/kibana, get 404. Or I misunderstand concepts of rewrite rules, I would need help for it.

UPDATED:

if I change to servicePort to 80, path for /logger, it works, but /kibana still return default backend - 404

-- john chan
kubernetes
kubernetes-ingress

0 Answers