Minikube ingress controller not forwarding request to deployed service properly

4/23/2020

I have following setup in minikube cluster

  1. SpringBoot app deployed in minikube cluster

name : opaapp and containerPort: 9999

  1. Service use to expose service app as below
apiVersion: v1
kind: Service
metadata:
  name: opaapp
  namespace: default
  labels:
    app: opaapp
spec:
  selector:
    app: opaapp
  ports:
    - name: http
      port: 9999
      targetPort: 9999
  type: NodePort
  1. Created an ingreass controller and ingress resource as below
apiVersion: networking.k8s.io/v1beta1 # for versions before 1.14 use extensions/v1beta1
kind: Ingress
metadata:
  name: opaapp-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
  rules:
  - host: opaapp.info
    http:
      paths:
      - path: /
        backend:
          serviceName: opaapp
          servicePort: 9999

I have setup host file as below

172.17.0.2    opaapp.info

Now, if I access service as below

http://opaapp.info:32746/api/ping : I am getting the response back

But if I try to access as

http://opaapp.info/api/ping : Getting 404 error

Not able to find the error on configuration

-- ajoy sinha
kubernetes
kubernetes-ingress
kubernetes-service
minikube
nginx-ingress

1 Answer

4/23/2020

The nginx ingress controller has been exposed via NodePort 32746 which means nginx is not listening on port 80/443 in the host's(172.17.0.2) network, rather nginx is listening on port 80/443 on Kubernetes pod network which is different than host network. Hence accessing it via http://opaapp.info/api/ping is not working. To make it work the way you are expecting the nginx ingress controller need to be deployed with hostNetwork: true option so that it can listen on 80/443 port directly in the host(172.17.0.2) network which can be done as discussed here.

-- Arghya Sadhu
Source: StackOverflow