<p>I have 2 Pods with 1 container each. The container names are:</p>
<ol>
<li>mc1</li>
<li>mc2</li>
</ol>
<p><strong>mc1</strong> container hosts an asp.net core razor pages app while <strong>mc2</strong> hosts a web api app. Now mc1 has to communicate with mc2 i.e. razor page app has to call web api app.</p>
<p>I have tried to explain it in the below image:
<a href="https://i.stack.imgur.com/2ZwiN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2ZwiN.png" alt="enter image description here" /></a></p>
<p>I created 2 deployments for these 2 pods:</p>
<pre><code>name: dep1
labels:
    app: mc-app1
spec:
  replicas: 1
  selector: 
    matchLabels:
      app: mc-app1
  template:
    metadata: 
      labels:
        app: mc-app1
    spec:
      containers:
        - name: mc1
          image: multiapp
          imagePullPolicy: Never
          ports:
            - containerPort: 80
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: dep2
  labels:
    app: mc-app2
spec:
  replicas: 1
  selector: 
    matchLabels:
      app: mc-app2
  template:
    metadata: 
      labels:
        app: mc-app2
    spec:
      containers:
        - name: mc2
          image: multiapi
          imagePullPolicy: Never
          ports:
            - containerPort: 80
</code></pre>
<p>I also created a service for the POD containing the mc2 container (i.e. web api app).</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: multi-container-service-2
spec:
  type: NodePort
  selector:
    app: mc-app2
  ports:
    - port: 8080
      targetPort: 80
</code></pre>
<p>The deployments and services are successfully applied to the k8s cluster.</p>
<p>Next, I am entering the container &quot;mc1&quot; and trying to curl the service called <strong>multi-container-service-2</strong> but this is not working.</p>
<p>I am getting error:</p>
<blockquote>
<p>curl: (7) Failed to connect to multi-container-service-2 port 80: Connection refused</p>
</blockquote>
<p>In the below image I am entering the shell of the container <strong>mc1</strong> with the command:</p>
<pre><code>kubectl exec -it dep1-5c78b8c889-tjzzr -c mc1 -- /bin/bash
</code></pre>
<p><a href="https://i.stack.imgur.com/tlLJe.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tlLJe.png" alt="enter image description here" /></a></p>
<p>In the next image I am doing the curl which is giving error:</p>
<p><a href="https://i.stack.imgur.com/wZoDD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wZoDD.png" alt="enter image description here" /></a></p>
<p>Note that I have already installed curl using the 2 commands given below:</p>
<pre><code>apt-get update
apt-get install curl
</code></pre>
<p>Why can't the app in mc2 container be called using the service? My Operating system is windows 10.</p>
<p>I am taking the help of these 2 tutorials:</p>
<ol>
<li><a href="https://learn.microsoft.com/en-us/dotnet/architecture/containerized-lifecycle/design-develop-containerized-apps/build-aspnet-core-applications-linux-containers-aks-kubernetes" rel="nofollow noreferrer">Build ASP.NET Core applications deployed as Linux containers into an AKS/Kubernetes orchestrator</a></li>
<li><a href="https://kubernetes.io/docs/tasks/access-application-cluster/communicate-containers-same-pod-shared-volume/" rel="nofollow noreferrer">Communicate Between Containers in the Same Pod Using a Shared Volume</a></li>
</ol>

yogihosting
<p>You have set to service port to <code>8080</code>, but you are calling the service on port 80 (which is the container's port).</p>
<p>This should work:</p>
<p><code>curl http://multi-container-service-2:8080</code></p>
