0

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
  • 1,156
  • 4
  • 14
  • 30

1 Answers1

2

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
  • 41,002
  • 9
  • 78
  • 107
  • Thanks for your input .. I got the point .. but my problem is .. in minikube I haven't installed ingress controller externally. I did enable ingress ..and set ingress resource through yml file . How can I set hostNetwork true in that case .. again thanks – ajoy sinha Apr 23 '20 at 16:58
  • I am not sure if this will work but you can try by editing the deployment of nginx ingress controller to add hostNetwork: true – Arghya Sadhu Apr 23 '20 at 17:00
  • I have updated the deployment with hostNetwork: true , and deploy it again. I can see it appears in pod level also. still getting the same error . Do i need to deploy the ingress resource and service again .. cause still http://opaapp.info/api/ping is not working – ajoy sinha Apr 23 '20 at 17:12
  • you updated the nginx ingress controller deployment not the opaapp deployment right? – Arghya Sadhu Apr 23 '20 at 17:15
  • Yes .. i found it from kube-system namespace and update it there .. restartPolicy: Always terminationGracePeriodSeconds: 60 dnsPolicy: ClusterFirst serviceAccountName: nginx-ingress serviceAccount: nginx-ingress hostNetwork: true securityContext: {} schedulerName: default-scheduler – ajoy sinha Apr 23 '20 at 17:17
  • check if a process is listening in the host on port 80/443 – Arghya Sadhu Apr 23 '20 at 17:21
  • Yes. nginx on ubuntu was running on 80 .. I did kill that one also .. but no luck ..same error – ajoy sinha Apr 23 '20 at 17:47
  • Thanks Arghya .. Thanks a lot... nice to meet you also .. it is working now .. I need to change annotation as and deployed it again annotations: kubernetes.io/ingress.class: "nginx" – ajoy sinha Apr 23 '20 at 17:52