0

I am running a kubernetes cluster on an openstack cloud and have a pod each for my angular frontend and my phoenix/elixir backend. When the user first calls the frontend through an ingress exposed node server, http calls to the backend are performed at the service level inside the kubernetes cluster and sent to the user. However, once the user navigates in the angular 8 environment, the http calls go directly to the same url the kubernetes services used to communicate, thus failing to resolve the address. So is it absolutely necessary to expose the backend api endpoint to the internet in order for the user to be able to get around the site ? Or is there a way to pipe everything through the frontend ingress access point ?

On request:

The ingress.yaml is:

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: ingress
  annotations:
    kubernetes.io/ingress.class: "nginx"
spec:
  rules:
  - host: 
    http:  
      paths:
      - path: /api
        backend:
          serviceName: webapp
          servicePort: 8000
      - path: /
        backend:
          serviceName: frontend
          servicePort: 8200

Regarding the http calls, the auth service does this to login:

login({ email, password }): Observable<User> {
    const params = {
      data: { attributes: { email: email, password: password } }
    };
    return this.http.post<{ data: User }>('login', params).pipe(
      map(({ data: user }) => {
        this.setTokenInLocalStorage(user, 'user');
        this.store.dispatch(
          this.actions.getCurrentUserSuccess(
            JSON.parse(localStorage.getItem('user'))
          )
        );
        this.store.dispatch(this.actions.loginSuccess());
        return user;
      }),
      tap(
        _ => this.router.navigate(['/']),
        error => this.toastrService.error(error.error.errors.detail, 'ERROR!')
      ),
      catchError(error => {
        return of(error);
      }) as any
    );
  }
  • please, please provide the ingress rule and show how your frontend calls the backend – c4f4t0r May 08 '20 at 15:08
  • @c4f4t0r: I edited the question along the lines of your comment. – Paul Rousseau May 08 '20 at 15:35
  • The question is really about understanding at which point the api has to be available to both the frontend service in the cluster and the client at the same time, thus making a common address for both necessary. – Paul Rousseau May 08 '20 at 15:46
  • And where is this configured ? – Paul Rousseau May 08 '20 at 15:55
  • the /api need to be expose depending on your needs, if your api service need to be consume only buy you, don't expose them, from your frontend to call the api you can use the wepapp kuberneted service dns name – c4f4t0r May 08 '20 at 22:07

0 Answers0