<p>I am new to Kubernetes and I'm trying to deploy an application to kubernetes via microk8s. The application contains python flask backend, angular frontend, redis and mysql database. I deployed the images in multiple pods and the status is showing "running" but the pods are not communicating with each other. </p>

<p>Then app is completely dockerized and its functioning in the docker level. 
Before deploying into kubernetes my flask host was 0.0.0.0 and mysql host was "service name" in the docker-compose.yaml but currently I replaced it with service names of kubernetes yml file.</p>

<p>Also, in angular frontend I have changed the url to connect to backed as   <a href="http://localhost:5000" rel="nofollow noreferrer">http://localhost:5000</a> to <a href="http://backend-service" rel="nofollow noreferrer">http://backend-service</a>, where backend-service is the name(dns) given in the backend-service.yml file. But this also didn't make any change. Can someone tell me how can I make these pods communicate?</p>

<p>I am able to access only the frontend after deploying rest is not connected.</p>

<p>Listing down the service and deployment files of angular, backend.</p>

<pre><code> apiVersion: v1
 kind: Service
 metadata:
   name: angular-service
 spec:
   type: NodePort
   selector:
     name: angular
   ports:
     - protocol: TCP
       nodePort: 30042
       targetPort: 4200
       port: 4200
</code></pre>

<hr>

<pre><code> apiVersion: v1
 kind: Service
 metadata:
   name: backend-service
 spec:
   type: ClusterIP
   selector:
     name: backend
   ports:
     - protocol: TCP
       targetPort: 5000
       port: 5000
</code></pre>

<p>Thanks in advance!</p>

<p>(<strong>Modified service files</strong>)</p>

<p><em>For internal communication between different microservices in <strong>Kubernetes</em></strong> you should use <code>Service</code> of a type <a href="https://kubernetes.io/docs/concepts/services-networking/connect-applications-service/#creating-a-service" rel="noreferrer">ClusterIP</a>. It is actually the <strong>default type</strong> so even if you don't specify it in your <code>Service</code> yaml definition file, <strong>Kubernetes</strong> assumes you want to create <code>ClusterIP</code>. 
It creates virtual internal IP (accessible within your Kubernetes cluster) and exposes your cluster component (microservice) as a <em>single entry point</em> even if it is backed up by many pods. </p>

<p>Let's assume you have front-end app which needs to communicate with back-end component which is run in 3 different pods. <code>ClusterIP</code> service provides single entry point and handles load-balancing between different pods, distributing requests evenly among them.</p>

<p>You can access your <code>ClusterIP</code> service by providing its IP address and port that your application component is exposed on. Note that you may define a different port (referred to as <code>port</code> in <code>Service</code> definition) for the <code>Service</code> to listen on than the actual port used by your application (referred to as <code>targetPort</code> in your <code>Service</code> definition). Although it is possible to access the <code>Service</code> using its <code>ClusterIP</code> address, all components that communicate with pods internally exposed by it <strong>should use its DNS name</strong>. It is simply a <code>Service</code> name that you created if all application components are placed in the same namespace. If some components are in a different namespaces you need to use fully qualified domain name so they can communicate across the namespaces.</p>

<p>Your <code>Service</code> definition files may look like this:</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: angular-service
spec:
  type: ClusterIP ### may be ommited as it is a default type
  selector:
    name: angular ### should match your labels defined for your angular pods
  ports:
  - protocol: TCP
    targetPort: 4200 ### port your angular app listens on
    port: 4200 ### port on which you want to expose it within your cluster

apiVersion: v1
kind: Service
metadata:
  name: backend-service
spec:
  type: ClusterIP ### may be ommited as it is a default type
  selector:
    name: backend ### should match your labels defined for your backend pods
  ports:
  - protocol: TCP
    targetPort: 5000 ### port your backend app listens on
    port: 5000 ### port on which you want to expose it within your cluster
</code></pre>

<p>You can find a detailed description of this topic in official <strong>Kubernetes</strong> <a href="https://kubernetes.io/docs/concepts/services-networking/connect-applications-service/" rel="noreferrer">documentation</a>.</p>

<hr>

<p><code>NodePort</code> has totally different function. It may be used e.g. to expose your front-end app on a specific port on your node's IP. Note that if you have Kubernetes cluster consisting of many nodes and your front-end pods are placed on different nodes, in order to access your application you need to use 3 different IP addresses. In such case you need an additional load balancer. If you use some cloud platform solution and you want to expose front-end part of your application to external world, Service type <a href="https://kubernetes.io/docs/tasks/access-application-cluster/create-external-load-balancer/" rel="noreferrer">LoadBalancer</a> is the way to go (instead of using <code>NodePort</code>).</p>
