<p>I am trying to create a pod with 2 containers each having different images! Am not sure how to expose the two different containers to the client. Following is my yaml file for deployment.</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: checkdifimage
spec:
  replicas: 1
  template: 
metadata:
  labels:
    app: checkdifimagelab
spec:
  containers:
  - name: checkallcont1
    image: &lt;dockerimage&gt;
    ports:
    - containerPort: 32030
  - name: checkall1cont2
    image: &lt;dockerimage2&gt;
    ports:
    - containerPort: 32031
</code></pre>

<p>What am currently doing is after I have the deployment up. I run the following command to expose the service :</p>

<pre><code>kubectl expose pod checkdifimage --port=8080 --type=NodePort --name=diffimage
</code></pre>

<p>This works for a single container and am able to hit the service from a rest client. But when I use 2 containers, i am only able to hit one container. How should I proceed to hit both the containers? Also, if someone can please guide on what are the advantages and disadvantages of using one pod having one image vs one pod having multiple images!</p>

<p>You have multiple Options:</p>

<ol>
<li><p>Create multiple services exposing one port each, on the same deployment.</p></li>
<li><p>Create single service exposing multiple ports:</p>

<pre><code>---
kind: Service
apiVersion: v1
metadata:
  name: my-service
spec:
  selector:
    app: MyApp
  ports:
  - name: http
    protocol: TCP
    port: 80
    targetPort: 9376
  - name: https
    protocol: TCP
    port: 443
    targetPort: 9377
</code></pre></li>
<li><p>Using kubectl expose:</p>

<pre><code>kubectl expose service nginx --port=443 --target-port=8443 --name=nginx-https
</code></pre></li>
</ol>

<blockquote>
  <p>Note that if no port is specified via –port and the exposed resource has multiple ports, all will be re-used by the new service. Also if no labels are specified, the new service will re-use the labels from the resource it exposes.</p>
</blockquote>

<p><a href="https://kubernetes.io/docs/user-guide/kubectl/kubectl_expose/" rel="noreferrer">Source</a></p>

<p>When to use multi container pods:
A pod is a group of one or more containers, the shared storage for those containers, and options about how to run the containers. Pods are always <strong>co-located</strong> and <strong>co-scheduled</strong>, and run in a shared context. A pod models an application-specific “logical host” - it contains one or more application containers which are <strong>relatively tightly coupled</strong> — in a pre-container world, they would have executed on the same physical or virtual machine.</p>

<p><a href="https://i.stack.imgur.com/cpipG.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/cpipG.jpg" alt="enter image description here"></a></p>
