Not able to connect to back-end using minikube

6/9/2019

I am trying to deploy an application in minikube locally . When i start the minikube , I am able to connect to the front-end, but NOT the back end.

Below are the yaml files

Ingress

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress-service
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
    - http:
        paths:
          - path: /
            backend:
              serviceName: client-cluster-ip-service
              servicePort: 3000
          - path: /api/
            backend:
              serviceName: server-cluster-ip-service
              servicePort: 8080

UI-deployment

apiVersion: apps/v1
kind: Deployment
metadata:
  name: client-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      component: web

  template:
    metadata:
      labels:
        component: web
    spec:
      containers:
        - name: client
          image: registry.gitlab.com/test/test1/test2/app-UI
          ports:
            - containerPort: 3000
      imagePullSecrets:
        - name: gitlab-auth

UI-service

apiVersion: v1
# sets up networking in kubernetes cluster
kind: Service
metadata:
  name: client-cluster-ip-service
spec:
  selector:
    component: web
  ports:
    - port: 3000
      targetPort: 3000

backend-deployment

apiVersion: apps/v1
kind: Deployment
metadata:
  name: server-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      component: server
  template:
    metadata:
      labels:
        component: server
    spec:
      containers:
        - name: server
          image: registry.gitlab.com/test1/test2/test3/test4-api
          ports:
            - containerPort: 8080
      imagePullSecrets:
        - name: gitlab-auth

Backend-Service

apiVersion: v1
kind: Service
metadata:
  name: server-cluster-ip-service
spec:
  type: ClusterIP
  selector:
    component: server
  ports:
    - port: 8080
      targetPort: 8080

I keep getting the below error on the browser

POST https://192.168.99.111/api/auth/login 404
dispatchXhrRequest  @   xhr.js:155
xhrAdapter  @   xhr.js:16
dispatchRequest @   dispatchRequest.js:49
Promise.then (async)        
request @   Axios.js:55
Axios.<computed>    @   Axios.js:74
wrap    @   bind.js:11
(anonymous) @   LoginForm.tsx:34
callback    @   createBaseForm.js:554
(anonymous) @   createBaseForm.js:579
validateFields  @   createBaseForm.js:541
LoginForm.handleSubmit  @   LoginForm.tsx:17
callCallback    @   react-dom.development.js:147
invokeGuardedCallbackDev    @   react-dom.development.js:196
invokeGuardedCallback   @   react-dom.development.js:250
invokeGuardedCallbackAndCatchFirstError @   react-dom.development.js:265
executeDispatch @   react-dom.development.js:571
executeDispatchesInOrder    @   react-dom.development.js:596
executeDispatchesAndRelease @   react-dom.development.js:695
executeDispatchesAndReleaseTopLevel @   react-dom.development.js:704
forEachAccumulated  @   react-dom.development.js:676
runEventsInBatch    @   react-dom.development.js:844
runExtractedEventsInBatch   @   react-dom.development.js:852
handleTopLevel  @   react-dom.development.js:5029
batchedUpdates$1    @   react-dom.development.js:21463
batchedUpdates  @   react-dom.development.js:2247
dispatchEvent   @   react-dom.development.js:5109
(anonymous) @   react-dom.development.js:21520
unstable_runWithPriority    @   scheduler.development.js:255
interactiveUpdates$1    @   react-dom.development.js:21519
interactiveUpdates  @   react-dom.development.js:2268
dispatchInteractiveEvent    @   react-dom.development.js:5085

1) When i run the app without minikube the application runs fine.
2) When i run the app with minikube and hit https://192.168.99.111 , the front end comes up fine.
3) As soon as i try to hit login button and app tries to connect to backend , i get the above error.
4) For some reason its not able to connect to backend when running on minikube and i keep getting resource not found error.

192.168.99.111 is the minikube ip

I am brand new to kubernetes and any help in debugging is highly appreciated.

Update

I think its some issue with ingress controller When i see in ingress controller logs it showed

192.168.99.1 - [192.168.99.1] - - [10/Jun/2019:00:07:58 +0000] "POST /api/auth/login HTTP/1.1" 404 19 "http://192.168.99.116/auth/login?redirect=/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36" 520 0.001 [default-server-cluster-ip-service-8080] 172.17.0.8:8080 19 0.002 404 702298110b92307929f9817bb50c47ff

instead of http://192.168.99.116/auth/login?redirect=/, it should have been http://192.168.99.116/api/auth/login?redirect=/

Why is /api getting dropped?

-- Fakeer
kubernetes
kubernetes-ingress
minikube
node.js
reactjs

2 Answers

6/11/2019

There is no problem with your ingress configuration. Your backend application has rule to redirect itself to /auth/login path and it can't be solved via Ingress controller if you want to add prefix. You have to configure your backend API to handle those URLs by app code.

-- coolinuxoid
Source: StackOverflow

6/10/2019

This is what nginx.ingress.kubernetes.io/rewrite-target: / do for you. It remove the prefix in your ingress config. You could remove this annotation to keep /api/ in the path.

See this: https://github.com/kubernetes/ingress-nginx/tree/master/docs/examples/rewrite

-- Fei
Source: StackOverflow