<p>i did my kubernetes setup using minikube on my ubuntu machine.
I started minkube cluster and am able to start front-end and backend PODs and correspondingly their services <strong>(Type- ClusterIP)</strong> as well.</p>
<p>I have <strong>setup Ingress</strong> as well  which allowing me to hit the Front-end service(Angular codebase running on Nginx).</p>
<p>Issue i am facing is i am able to hit the front-end POD through Ingress but front-end POD not able to call the backend POD <strong>(Having code on agnular side which tries to invoke backend api)</strong></p>
<p><strong>Angular side code, base URL defined as:</strong></p>
<pre><code>export class HeroService {

  private baseUrl = 'http://backend-cluster-ip-service';  
  private apiUrl = `${this.baseUrl}/heroapi/heroes`;

  constructor(private http: HttpClient, private messageService: MessageService) { }

  httpOptions = {
    headers: new HttpHeaders({ 'Content-Type': 'application/json' })
  };

  /** GET heroes from the server */
  getHeroes(): Observable&lt;Hero[]&gt;{
    /* const heroes = of(HEROES);
    return heroes; */
    return this.http.get&lt;Hero[]&gt;(this.apiUrl)
    .pipe(
      catchError(this.handleError&lt;Hero[]&gt;('getHeroes', []))
    );
  }
</code></pre>
<p>Getting below issue while trying to invoke backend API.</p>
<p><a href="https://i.stack.imgur.com/6wlo3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6wlo3.png" alt="CORS issue" /></a></p>
<p><strong>I would like to make it clear i already enabled the CORS on backend side</strong>, please check the code below</p>
<pre><code> @Configuration
 public class CorsConfig {

 @Bean
    public WebMvcConfigurer corsConfigurer() {
        return new WebMvcConfigurerAdapter() {
            @Override
            public void addCorsMappings(CorsRegistry registry) {
                registry.addMapping(&quot;/**&quot;)
                .allowedOrigins(&quot;*&quot;)
                .allowedMethods(&quot;*&quot;);
            }
        };
    }
}
</code></pre>
<p><strong>Please see below configuration files for PODS, SERVICES, INGRESS and Docker files for both front-end and backend.</strong></p>
<p><strong>Angular Docker File(Dockerfile.prod):</strong></p>
<pre><code>#stage 1
FROM node:16-alpine as node
WORKDIR /app
COPY . .
RUN npm install
RUN npm run build --prod

#stage 2
FROM nginx:alpine
COPY --from=node /app/dist/sample_angular_first_app /usr/share/nginx/html
</code></pre>
<p><strong>Backend Docker file(Dockerfile.prod):</strong></p>
<pre><code>FROM adoptopenjdk/openjdk11:jre-11.0.11_9-alpine
WORKDIR /app
ARG JAR_FILE=./target/demo-0.0.1-SNAPSHOT.jar
COPY ${JAR_FILE} ./hero_app.jar
EXPOSE 8081
ENTRYPOINT [&quot;java&quot;,&quot;-jar&quot;,&quot;hero_app.jar&quot;]
</code></pre>
<p><strong>Angular(Front-end) Deployment Config file(client-deployment.yaml):</strong></p>
<pre><code>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: techlearning205docker/angular_hero_app_front_end:temp6
</code></pre>
<p><strong>Spring-boot(Back-end) Deployment Config file(backend-deployment.yaml):</strong></p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
    name: backend-deployment
spec:
    replicas: 1
    selector:
        matchLabels:
            component: backend-server
    template:
        metadata:
            labels:
                component: backend-server
        spec:
            containers:
                - name: hero-backend
                  image: techlearning205docker/heroapp_back_end:temp2
                  ports:
                  - containerPort: 8081
</code></pre>
<p><strong>Angular(Front-end) SERVICE Config file(client-cluster-ip-service.yaml):</strong></p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: client-cluster-ip-service
spec:
  type: ClusterIP
  ports:
    - port:  3050
      targetPort: 80
  selector:
    component:  web
</code></pre>
<p><strong>Spring boot(Back-end) SERVICE Config file(backend-cluster-ip-service.yaml):</strong></p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: backend-cluster-ip-service
spec:
  type: ClusterIP
  ports:
    - port:  3051
      targetPort: 8081
  selector:
    component:  backend-server
</code></pre>
<p><strong>Ingress config file(ingress-service.yaml)</strong></p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
    name: ingress-service
    annotations:
        kubernetes.io/ingress.class: 'nginx'
        nginx.ingress.kubernetes.io/use-regex: 'true'
        nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
  rules:
    - http:
        paths:
          - path: /?(.*)
            # UPDATE PATH
            pathType: Prefix
            # ADD PATHTYPE
            backend:
              service:
                # UPDATE SERVICE FIELDS
                name: client-cluster-ip-service
                port:
                  number: 3050
</code></pre>
<p>Please kindly help me to provide solution how one POD communicates with another POD if service type is CLUSTER IP, specifically for my case i have mentioned above.</p>

Qasim
<p>I got my above posted query resolved!</p>
<ul>
<li>Above issue i was facing due to the fact, we can not access the <strong>CLUSTER IP service</strong> (backend-cluster-ip-service) outside of cluster.</li>
<li>My assumption was we would be able to hit the One POD to another(if we try to invoke REST API(spring boot applicaiton running in another POD) from FrontEnd POD)</li>
<li>Above point is actually true when we hit request from <strong>within POD itself</strong></li>
<li><strong>But</strong> in case of <strong>FrontEnd POD(Angular code)</strong> its not happening due to below mentioned reasons</li>
<li>Since Angular is single page application, when we are hitting Url and request first recieved at Frontend side, whatever visible in browser that code is actually <strong>NOW on broswer side</strong> not on kubernetes cluster that means its on your local browser, Now when applicaiton tries to hit the REST api to some other server, Now this request actually being sent from <strong>browser(outside of the cluster)</strong> not from with in cluster.</li>
<li>That's the reason browser not able to resolve this request <strong>&quot;http://backend-cluster-ip-service&quot;</strong></li>
</ul>
<p><strong>TO Resolve the above issue, have simple workaround</strong></p>
<ul>
<li>The way we pass the request to <strong>front end(Angular POD)</strong> using <strong>Ingress</strong></li>
<li>Pass the <strong>backend</strong> via Ingress too.</li>
<li>Ingress should be intelligent enough to identify which request is for Angular POD and which is for Backend POD.</li>
</ul>
<p><strong>Below is the updated Ingress configuration file i have used.</strong></p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
    name: ingress-service
    annotations:
        kubernetes.io/ingress.class: 'nginx'
        nginx.ingress.kubernetes.io/use-regex: 'true'
        #nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
  rules:
    - http:
        paths:
          - path: /
            # UPDATE PATH
            pathType: Prefix
            # ADD PATHTYPE
            backend:
              service:
                # UPDATE SERVICE FIELDS
                name: client-cluster-ip-service
                port:
                  number: 3050
    - http:
        paths:
          - path: /heroapi
            # UPDATE PATH
            pathType: Prefix
            # ADD PATHTYPE
            backend:
              service:
                # UPDATE SERVICE FIELDS
                name: backend-cluster-ip-service
                port:
                  number: 3051
</code></pre>
<p><strong>I have also updated my Angular code</strong></p>
<ul>
<li><p>private baseUrl = 'http://backend-cluster-ip-service';</p>
</li>
<li><p>Update base url on angular side code with <strong>cluster ip</strong> in my case it was minikube ip(private baseUrl = 'http://192.168.49.2'; )</p>
</li>
<li><p>to avoid harcoding of cluster ip as it could change, we should handled it dynamically.</p>
</li>
</ul>
<p>If some one wants to try my above given configuration then please update the Angular POD deployment config image as well -&gt; <strong>techlearning205docker/angular_hero_app_front_end:minikube_ip_1</strong></p>
