0

I have a problem with my Angular 15 Frontend app inside Minikube cluster. For deploying my app in Minikube, I add the k8s services URLs to environment files and Angular/Nginx sends me back to localhost - not to desired servcice URL.

environment.development.ts

export const environment = {
    production: false,
    serviceURL: 'http://backend.namespace.svc.cluster.local:8000',

};
service.ts

import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Observable } from 'rxjs';
import { User } from './user';
import { environment } from '../../environments/environment'

@Injectable({
  providedIn: 'root'
})
export class MainService {

  baseUrl = environment.serviceURL+'/user/'
  httpHeaders = new HttpHeaders;

  constructor(
    private http: HttpClient,
  ) { }

  user(user:any): Observable<User> {
    return this.http.get<User>(this.baseUrl)
  }
}

With these settings Angular sends me back to localhost, where I get an 404 error where cannot find the 'http://localhost:4200/user/'

When I try to curl service url ( curl http://backend.namespace.svc.cluster.local:8000 ) from frontend pod I get a correct response.

Can someone advise me how to correctly connect angular frontend with django backend, please?

1 Answers1

0

The service running on your host must either be bound to all IP’s (0.0.0.0) and interfaces, or to the IP and interface your VM is bridged against. If the service is bound only to localhost (127.0.0.1), this will not work.

Following the minikube documentation, it's correct that you can't reach the services via localhost without doing any configuration.

To make it easier to access your host, minikube v1.10 adds a hostname entry host.minikube.internal to /etc/hosts. The IP which host.minikube.internal resolves to is different across drivers, and may be different across clusters.

https://minikube.sigs.k8s.io/docs/handbook/host-access/#hostminikubeinternal

glv
  • 994
  • 1
  • 1
  • 15