<p>I am new to Docker and Kubernetes.
Technologies used:</p>

<ul>
<li>Dotnet Core 2.2</li>
<li>Asp.NET Core WebAPI 2.2</li>
<li>Docker for windows(Edge) with Kubernetes support enabled</li>
<li><a href="https://github.com/vkgpt11/StackOverFlowSuppot/tree/master/DotnetCore" rel="nofollow noreferrer">Code</a> </li>
</ul>

<p>I am having two services hosted into two docker containers container1 and container2. </p>

<p>Below is my deploy.yaml</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: webapi-dockerkube
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: webapi-dockerkube
    spec:
      containers:
      - name: webapi-dockerkube
        image: "webapidocker:latest"
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 80
        livenessProbe:
          httpGet:
            path: /api/values
            port: 80
        readinessProbe:
          httpGet:
            path: /api/values
            port: 80
      - name: webapi-dockerkube2
        image: "webapidocker2:latest"
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 80
        livenessProbe:
          httpGet:
            path: /api/other/values
            port: 80
        readinessProbe:
          httpGet:
            path: /api/other/values
            port: 80
</code></pre>

<p>When I am running command:</p>

<pre><code>kubectl create -f .\deploy.yaml
</code></pre>

<p>I am getting status as <code>CrashLoopBackOff</code>. </p>

<p>But same is running fine when i have only one container configured.
When checking logs I am getting following error:
<code>Error from server (BadRequest): a container name must be specified for pod webapi-dockerkube-8658586998-9f8mk, choose one of: [webapi-dockerkube webapi-dockerkube2]</code></p>

<p>You are running two containers in the same pod which bind both to port 80. This is not possible within the same pod.
Think of a pod like a 'server' and you can't have two processes bind to the same port.</p>

<p>Solution in your situation: Use different ports inside the pod or use separate pods. From your deployment there seems to be no shared resources like filesystem, so it would be easy to split the containers to separate pods.</p>

<p>Note that it will not suffice to change the pod definition if you want to have both containers running in the same pod with different ports. The application in the container must bind to a different port as well. </p>
