Minikube Ingress (Nginx Controller) not working

890 views Asked by At

I have a spring boot application deployed to minikube. The application has a get mapping exposed as -

@GetMapping("/ping")
    public String get(){
        return "Hello !!";
    }

Created and applied the deployment and the service. Both are fine and the demo-app container is also running in the cluster.

Deployment manifest

apiVersion: apps/v1
kind: Deployment
metadata:
  name: demo-app-deployment
  labels:
    app: demo-app
spec:
  selector:
    matchLabels:
      app: demo-app
  replicas: 1
  template:
    metadata:
      labels:
        app: demo-app
    spec:
      imagePullSecrets:
      - name: regcred
      containers:
      - name: demo-app
        image: <<image>>
        imagePullPolicy: Always
        ports:
        - containerPort: 8080

Service manifest

apiVersion: v1
kind: Service
metadata:
  name: demo-app-service
spec:
  selector:
    app: demo-app
  ports:
  - protocol: TCP
    port: 8080
    targetPort: 8080

As the last step -

  1. Created the Ingress object in the minikube cluster using kubectl create -f ingress.yaml
  2. And mapped the minikube ip to this ingress host demo.com in Windows hosts file

Ingress manifest

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: demo-app-ingress
spec:
  rules:
    - host: demo.com
      http:
        paths:
          - path: /demo
            backend:
              serviceName: demo-app-service
              servicePort: 8080

While trying to access the app from browser, via http://demo.com/demo/ping it is giving whiteLabel Error Page enter image description here

Please help.

1

There are 1 answers

0
BeWu On

First what is happening: You specified that you wish to reach the service demo-app-service when you access the URI http://demo.com/demo . That part is working fine. The question here is which path is called on the service? I.e. the URI http://demo.com/demo/ping would request the endpoint /demo/ping in your service. I guess your ping service is locally accessible via the endpoint http://localhost:8080/ping . If that is the case all you need to do is add an annotation to the ingress to remove the /demo path from the request:

nginx.ingress.kubernetes.io/rewrite-target: /

See here for reference: https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations/#rewrite