<p>I am looking for help on how to add a second container to the existing pod (i mean one pod with two containers). The error is <strong>CrashLoopBackOff</strong>. I am using minikube. I request any assistance in resolving the issue will be appreciated.</p>

<pre><code>wordpress.yaml
--------XXXX------------------
apiVersion: v1
kind: Service
metadata:
  name: my-nginx-svc
  labels:
    app: nginx
spec:
  type: LoadBalancer
  ports:
  - port: 80
  selector:
    app: nginx
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-nginx
  labels:
    app: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2
        ports:
        - containerPort: 80
     - name: wordpress
        image: wordpress
        ports:
        - containerPort: 80
</code></pre>

<pre><code>#watch kubectl get pods

Every 2.0s: kubectl get pods                                                                                                                         cent8-minikube: Wed Jun 10 16:47:30 2020

NAME                            READY   STATUS             RESTARTS   AGE
my-nginx-6b474476c4-9p4cn       1/1     Running            0          5h41m
my-nginx-6b474476c4-m2xkd       1/1     Running            0          5h41m
my-nginx-9f44b5996-744n5        1/2     CrashLoopBackOff   9          21m
my-nginx-9f44b5996-vl6g2        1/2     CrashLoopBackOff   9          22m
test-minikube-f4df69575-2sbl5   1/1     Running            0          26h
</code></pre>

<pre><code>[root@cent8-minikube ~]# kubectl describe pod my-nginx-9f44b5996-vl6g2
Name:         my-nginx-9f44b5996-vl6g2
Namespace:    default
Priority:     0
Node:         cent8-minikube/192.168.194.128
Start Time:   Wed, 10 Jun 2020 16:25:14 -0700
Labels:       app=nginx
              pod-template-hash=9f44b5996
Annotations:  &lt;none&gt;
Status:       Running
IP:           172.17.0.8
IPs:
  IP:           172.17.0.8
Controlled By:  ReplicaSet/my-nginx-9f44b5996
Containers:
  nginx:
    Container ID:   docker://5e4cfd4e726373916a105a95644a7a286966482e33eaaac986e44514aef86606
    Image:          nginx:1.14.2
    Image ID:       docker-pullable://nginx@sha256:f7988fb6c02e0ce69257d9bd9cf37ae20a60f1df7563c3a2a6abe24160306b8d
    Port:           80/TCP
    Host Port:      0/TCP
    State:          Running
      Started:      Wed, 10 Jun 2020 16:25:16 -0700
    Ready:          True
    Restart Count:  0
    Environment:    &lt;none&gt;
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-lqnj8 (ro)
  wordpress:
    Container ID:   docker://5e37277badca1658a10d4d826428f538a45d5e0eaecabd5e196f8b6ab5848ec7
    Image:          wordpress
    Image ID:       docker-pullable://wordpress@sha256:ff8be61894e74b6a005ab54ba73aa7084b6dbd11605f12ac383549763918bf09
    Port:           80/TCP
    Host Port:      0/TCP
    State:          Waiting
      Reason:       CrashLoopBackOff
    Last State:     Terminated
      Reason:       Error
      Exit Code:    1
      Started:      Wed, 10 Jun 2020 16:46:37 -0700
      Finished:     Wed, 10 Jun 2020 16:46:38 -0700
    Ready:          False
    Restart Count:  9
    Environment:    &lt;none&gt;
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-lqnj8 (ro)
Conditions:
  Type              Status
  Initialized       True
  Ready             False
  ContainersReady   False
  PodScheduled      True
Volumes:
  default-token-lqnj8:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-lqnj8
    Optional:    false
QoS Class:       BestEffort
Node-Selectors:  &lt;none&gt;
Tolerations:     node.kubernetes.io/not-ready:NoExecute for 300s
                 node.kubernetes.io/unreachable:NoExecute for 300s
Events:
  Type     Reason     Age                   From                     Message
  ----     ------     ----                  ----                     -------
  Normal   Scheduled  23m                   default-scheduler        Successfully assigned default/my-nginx-9f44b5996-vl6g2 to cent8-minikube
  Normal   Pulled     23m                   kubelet, cent8-minikube  Container image "nginx:1.14.2" already present on machine
  Normal   Created    23m                   kubelet, cent8-minikube  Created container nginx
  Normal   Started    23m                   kubelet, cent8-minikube  Started container nginx
  Normal   Pulling    22m (x4 over 23m)     kubelet, cent8-minikube  Pulling image "wordpress"
  Normal   Pulled     22m (x4 over 23m)     kubelet, cent8-minikube  Successfully pulled image "wordpress"
  Normal   Created    22m (x4 over 23m)     kubelet, cent8-minikube  Created container wordpress
  Normal   Started    22m (x4 over 23m)     kubelet, cent8-minikube  Started container wordpress
  Warning  BackOff    3m35s (x95 over 23m)  kubelet, cent8-minikube  Back-off restarting failed container
[root@cent8-minikube ~]#
</code></pre>

<pre><code>[root@cent8-minikube ~]# kubectl describe pod my-nginx-9f44b5996-744n5
Name:         my-nginx-9f44b5996-744n5
Namespace:    default
Priority:     0
Node:         cent8-minikube/192.168.194.128
Start Time:   Wed, 10 Jun 2020 16:25:33 -0700
Labels:       app=nginx
              pod-template-hash=9f44b5996
Annotations:  &lt;none&gt;
Status:       Running
IP:           172.17.0.10
IPs:
  IP:           172.17.0.10
Controlled By:  ReplicaSet/my-nginx-9f44b5996
Containers:
  nginx:
    Container ID:   docker://9e3d6f0073e51eb475c2f2677fa413509f49a07c955d04b09417811d37ba8433
    Image:          nginx:1.14.2
    Image ID:       docker-pullable://nginx@sha256:f7988fb6c02e0ce69257d9bd9cf37ae20a60f1df7563c3a2a6abe24160306b8d
    Port:           80/TCP
    Host Port:      0/TCP
    State:          Running
      Started:      Wed, 10 Jun 2020 16:25:35 -0700
    Ready:          True
    Restart Count:  0
    Environment:    &lt;none&gt;
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-lqnj8 (ro)
  wordpress:
    Container ID:   docker://2ca8f22ab14b88973dca8d4d486f82a5b0d9bc7b84960882cff0a81afd744bf4
    Image:          wordpress
    Image ID:       docker-pullable://wordpress@sha256:ff8be61894e74b6a005ab54ba73aa7084b6dbd11605f12ac383549763918bf09
    Port:           80/TCP
    Host Port:      0/TCP
    State:          Waiting
      Reason:       CrashLoopBackOff
    Last State:     Terminated
      Reason:       Error
      Exit Code:    1
      Started:      Wed, 10 Jun 2020 16:46:41 -0700
      Finished:     Wed, 10 Jun 2020 16:46:42 -0700
    Ready:          False
    Restart Count:  9
    Environment:    &lt;none&gt;
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-lqnj8 (ro)
Conditions:
  Type              Status
  Initialized       True
  Ready             False
  ContainersReady   False
  PodScheduled      True
Volumes:
  default-token-lqnj8:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-lqnj8
    Optional:    false
QoS Class:       BestEffort
Node-Selectors:  &lt;none&gt;
Tolerations:     node.kubernetes.io/not-ready:NoExecute for 300s
                 node.kubernetes.io/unreachable:NoExecute for 300s
Events:
  Type     Reason     Age                  From                     Message
  ----     ------     ----                 ----                     -------
  Normal   Scheduled  26m                  default-scheduler        Successfully assigned default/my-nginx-9f44b5996-744n5 to cent8-minikube
  Normal   Pulled     26m                  kubelet, cent8-minikube  Container image "nginx:1.14.2" already present on machine
  Normal   Created    26m                  kubelet, cent8-minikube  Created container nginx
  Normal   Started    26m                  kubelet, cent8-minikube  Started container nginx
  Normal   Pulling    25m (x4 over 26m)    kubelet, cent8-minikube  Pulling image "wordpress"
  Normal   Pulled     25m (x4 over 26m)    kubelet, cent8-minikube  Successfully pulled image "wordpress"
  Normal   Created    25m (x4 over 26m)    kubelet, cent8-minikube  Created container wordpress
  Normal   Started    25m (x4 over 26m)    kubelet, cent8-minikube  Started container wordpress
  Warning  BackOff    67s (x116 over 26m)  kubelet, cent8-minikube  Back-off restarting failed container
[root@cent8-minikube ~]#
</code></pre>

<pre><code>``` [root@cent8-minikube ~]# kubectl logs my-nginx-9f44b5996-vl6g2 -c wordpress WordPress not found in /var/www/html - copying now... Complete! WordPress has been successfully copied to /var/www/html AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.8. Set the 'ServerName' directive globally to suppress this message (98)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:80 no listening sockets available, shutting down AH00015: Unable to open logs 
</code></pre>

<ol>
<li>How to add a second container to the pod?</li>
<li>where to check the logs of the crash container or How to debug?</li>
<li>could you guide me, how to fix this error?</li>
</ol>

Dan
<p>The important part of your error is this:</p>

<pre class="lang-none prettyprint-override"><code>Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:80 no listening sockets available, shutting down
</code></pre>

<p>If you run multiple containers in a single pod, they share a network namespace.  Where the Service forwards to port 80 of the pod, it could reach any container.  In this example, that means you can't have two containers in the same pod listening to the same port.</p>

<p>A better practice would be to split these two components into two separate Deployments, each with a matching Service.  To do this:</p>

<ol>
<li>Make two copies of your existing Deployment.  In one, delete all mentions of Wordpress.  In the other, delete the Nginx container and otherwise globally replace <code>nginx</code> with <code>wordpress</code>.</li>
<li>Make two copies of your existing Service.  Change the second one to be <code>type: ClusterIP</code>, and globally replace <code>nginx</code> with <code>wordpress</code>.</li>
<li>In your Nginx proxy configuration, where you <code>proxy_pass</code> to the Wordpress container, change its backend to <code>http://my-wordpress-svc/</code>.</li>
</ol>

<p>It would be very routine to wind up with 5 separate YAML files for this (two Deployments, two Services, one ConfigMap) and you can run <code>kubectl apply -f</code> on a directory to install them all in one shot.</p>
