<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>To check logs of a container in a pod</p>

<pre><code>kubectl logs my-pod -c my-container 
</code></pre>

<p>To check logs of previous instance of a  container in a pod</p>

<pre><code>kubectl logs my-pod -c my-container --previous 
</code></pre>

<p>In your case this will translate to</p>

<pre><code> kubectl logs my-nginx-9f44b5996-vl6g2 -c nginx
 kubectl logs my-nginx-9f44b5996-vl6g2 -c wordpress
</code></pre>

<p>Wordpress is probably not a good idea to run with nginx in the same pod. Check this guide on <a href="https://kubernetes.io/docs/tasks/access-application-cluster/communicate-containers-same-pod-shared-volume/#creating-a-pod-that-runs-two-containers" rel="nofollow noreferrer">multicontainer pod</a></p>

<p>Check this <a href="https://kubernetes.io/docs/tutorials/stateful-application/mysql-wordpress-persistent-volume/" rel="nofollow noreferrer">guide</a> to run wordpress on kubernetes </p>
