<p>I have a pod with 3 containers A, B, and C. I would like to access service in Container A and B from C. Neither <code>localhost:&lt;port&gt;</code> is working nor the <code>127.0.0.1</code>.</p>

<p>my yaml </p>

<pre><code>apiVersion: "v1"
kind: Pod
metadata:
  name: web3
  labels:
    name: web
    app: demo
spec:
  containers:
    - name: client
      image: ubuntu
      command: ['cat']
      tty: true
    - name: apache1
      image: nimmis/apache-php5
      ports:
        - containerPort: 8080
          name: apacheport1
          protocol: TCP
    - name: apache2
      image: nimmis/apache-php5
      command: ['cat']
      tty: true
      ports:
        - containerPort: 8088
          name: apacheport2
          protocol: TCP
</code></pre>

<p>what I am doing</p>

<pre><code>kubectl apply -f example.yaml
kubectl exec -it web3 -c client bash
</code></pre>

<p>and then try to reach other 2 services</p>

<pre><code>root@web3:/# curl http://localhost:8080
curl: (7) Failed to connect to localhost port 8080: Connection refused
root@web3:/# curl http://localhost:8088
curl: (7) Failed to connect to localhost port 8088: Connection refused
root@web3:/# curl http://localhost:80

&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;!--
    Modified from the Debian original for Ubuntu

</code></pre>

<p>Questions
 How to make the first 2 curl work. (I do not want to use the service since my use case is only for testing purpose)
 Why there is an open port 80 when I haven't exposed the port.</p>

Ram
<p>The point is that with <code>nimmis/apache-php5</code> Apache is listening on port 80.
So, it's port 80 which is exposed.
Through <code>containerPort: &lt;P&gt;</code> you are not saying to expose container's port 80 to <code>&lt;P&gt;</code>, but rather exposing port <code>&lt;P&gt;</code> itself. Also, as written in the docs, <code>Not specifying a port here DOES NOT prevent that port from being exposed.</code>.</p>

<p>I did not find a way to map an internal container port to a different port in the pod. However, you may map the internal container port to a host port through field <code>hostPort</code>.</p>

<pre><code>apiVersion: "v1"
kind: Pod
metadata:
name: web3
labels:
name: web
app: demo
spec:
containers:
- name: client
  image: ubuntu
  command: ['cat']
  tty: true
- name: apache1
  image: nimmis/apache-php5
  ports:
    - containerPort: 80
      name: apacheport1
      hostPort: 8002
      protocol: TCP
- name: apache2
  image: nimmis/apache-php5
  command: ['cat']
  tty: true
  ports:
    - containerPort: 80
      hostPort: 8001
      name: apacheport2
      protocol: TCP
</code></pre>

<p>Then you get the IP of the node, e.g., on Minikube</p>

<pre><code>$ minikube ip  # e.g., 192.168.97.100
</code></pre>

<p>and check that, from <code>client</code>, you can access the Apache services:</p>

<pre><code>$ kubectl exec -it web3 -c client bash
# apt-get update &amp;&amp; apt-get install curl
# curl 192.168.99.100:8002 
</code></pre>
