<p>I try to deploy mysql container in Kubernetes cluster (minikube) using the <a href="https://kubernetes.io/docs/tutorials/stateful-application/mysql-wordpress-persistent-volume/" rel="nofollow noreferrer">example</a>.</p>
<p>I changed only a following part:</p>
<pre><code>apiVersion: v1
kind: PersistentVolume
metadata:
  name: mysql-pv-volume
  labels:
    type: local
spec:
  storageClassName: manual
  capacity:
    storage: 20Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: &quot;/Users/tomasz/k8s/volume&quot;
</code></pre>
<p>I doublechecked if the directory exists. Yes it does.</p>
<p>However, the container doesn't work because the command:</p>
<pre><code>kubectl get pods
</code></pre>
<p>prints</p>
<pre><code>NAME                           READY   UP-TO-DATE   AVAILABLE   AGE
mysql                          0/1     1            0           26d
phpmyadmin                     1/1     1            1           26d
</code></pre>
<p>when I use:</p>
<pre><code>kubectl describe pod mysql-6f9cd7b9df-vj2zf
</code></pre>
<p>I get:</p>
<pre><code>Name:             mysql-6f9cd7b9df-vj2zf
Namespace:        default
Priority:         0
Service Account:  default
Node:             minikube/192.168.64.2
Start Time:       Sun, 23 Jul 2023 21:09:02 +0200
Labels:           app=mysql
                  pod-template-hash=6f9cd7b9df
Annotations:      &lt;none&gt;
Status:           Running
IP:               10.244.0.120
IPs:
  IP:           10.244.0.120
Controlled By:  ReplicaSet/mysql-6f9cd7b9df
Containers:
  mysql:
    Container ID:   docker://d3f8152b3805a7e45153335935edfe46f6d9b800441a9d1e82953d1c87f3fb14
    Image:          mysql:5.6
    Image ID:       docker-pullable://mysql@sha256:20575ecebe6216036d25dab5903808211f1e9ba63dc7825ac20cb975e34cfcae
    Port:           3306/TCP
    Host Port:      0/TCP
    State:          Waiting
      Reason:       CrashLoopBackOff
    Last State:     Terminated
      Reason:       Error
      Exit Code:    137
      Started:      Sat, 19 Aug 2023 11:36:22 +0200
      Finished:     Sat, 19 Aug 2023 11:38:13 +0200
    Ready:          False
    Restart Count:  21
    Environment:
      MYSQL_ROOT_PASSWORD:  &lt;set to the key 'mysql-root-password' in secret 'mysql-secret'&gt;  Optional: false
    Mounts:
      /var/lib/mysql from mysql-persistent-storage (rw)
      /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-52qf5 (ro)
Conditions:
  Type              Status
  Initialized       True 
  Ready             False 
  ContainersReady   False 
  PodScheduled      True 
Volumes:
  mysql-persistent-storage:
    Type:       PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
    ClaimName:  mysql-pv-claim
    ReadOnly:   false
  kube-api-access-52qf5:
    Type:                    Projected (a volume that contains injected data from multiple sources)
    TokenExpirationSeconds:  3607
    ConfigMapName:           kube-root-ca.crt
    ConfigMapOptional:       &lt;nil&gt;
    DownwardAPI:             true
QoS Class:                   BestEffort
Node-Selectors:              &lt;none&gt;
Tolerations:                 node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
                             node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
  Type     Reason           Age                 From               Message
  ----     ------           ----                ----               -------
  Normal   Scheduled        26d                 default-scheduler  Successfully assigned default/mysql-6f9cd7b9df-vj2zf to minikube
  Normal   Pulled           26d (x5 over 26d)   kubelet            Container image &quot;mysql:5.6&quot; already present on machine
  Normal   Created          26d (x5 over 26d)   kubelet            Created container mysql
  Normal   Started          26d (x5 over 26d)   kubelet            Started container mysql
  Warning  BackOff          26d (x89 over 26d)  kubelet            Back-off restarting failed container mysql in pod mysql-6f9cd7b9df-vj2zf_default(7d26ac38-3f3c-49e9-a5b5-e1399a2df0e6)
  Warning  NetworkNotReady  14d (x2 over 14d)   kubelet            network is not ready: container runtime network not ready: NetworkReady=false reason:NetworkPluginNotReady message:docker: network plugin is not ready: cni config uninitialized
  Warning  FailedMount      14d (x4 over 14d)   kubelet            MountVolume.SetUp failed for volume &quot;kube-api-access-52qf5&quot; : object &quot;default&quot;/&quot;kube-root-ca.crt&quot; not registered
  Normal   SandboxChanged   14d                 kubelet            Pod sandbox changed, it will be killed and re-created.
  Normal   Started          14d (x3 over 14d)   kubelet            Started container mysql
  Normal   Pulled           14d (x4 over 14d)   kubelet            Container image &quot;mysql:5.6&quot; already present on machine
  Normal   Created          14d (x4 over 14d)   kubelet            Created container mysql
  Warning  BackOff          14d (x12 over 14d)  kubelet            Back-off restarting failed container mysql in pod mysql-6f9cd7b9df-vj2zf_default(7d26ac38-3f3c-49e9-a5b5-e1399a2df0e6)
  Normal   SandboxChanged   16m                 kubelet            Pod sandbox changed, it will be killed and re-created.
  Normal   Pulled           13m (x4 over 16m)   kubelet            Container image &quot;mysql:5.6&quot; already present on machine
  Normal   Created          13m (x4 over 16m)   kubelet            Created container mysql
  Normal   Started          13m (x4 over 16m)   kubelet            Started container mysql
  Warning  BackOff          95s (x48 over 15m)  kubelet            Back-off restarting failed container mysql in pod mysql-6f9cd7b9df-vj2zf_default(7d26ac38-3f3c-49e9-a5b5-e1399a2df0e6)
</code></pre>
<p>When I look into logs:</p>
<pre><code>kubectl logs -p mysql-6f9cd7b9df-vj2zf
</code></pre>
<p>I get:</p>
<pre><code>2023-08-19 09:36:22+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.6.51-1debian9 started.
2023-08-19 09:36:22+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2023-08-19 09:36:22+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.6.51-1debian9 started.
</code></pre>
<p>Could someone tell me how to debug it? Thank you.</p>

CodeGrinder
<p>Exit code 137 typically means that the process was terminated by a signal, and in Kubernetes, signal 137 corresponds to SIGKILL, which is often used to forcefully terminate a process.</p>
<p>There are a few common reasons why a MySQL container might be crashing like this:</p>
<p><strong>Resource Constraints:</strong> The MySQL container might not have enough resources (CPU, memory) assigned to it. This could lead to the process getting killed if it exceeds its resource limits.</p>
<p><strong>OOM (Out of Memory) Kill:</strong> If the container is running out of memory, the Linux kernel might invoke the OOM killer to terminate processes to free up memory.</p>
<p><strong>Configuration or Data Issues:</strong> If there are issues with the MySQL configuration or the data directory, it could cause the container to crash on startup.</p>
<p><strong>Volume Mounting Issues:</strong> The volume mounting might not be working as expected, which could cause the container to fail.</p>
<p><strong>Environment Variables:</strong> Make sure that the environment variables you're passing to the MySQL container, like the root password, are correctly set.</p>
<p>To debug this, you can try the following steps:</p>
<p><strong>Resource Allocation:</strong> Check if the resources allocated to the MySQL container are sufficient. You might need to increase the memory and CPU limits.</p>
<p><strong>Memory Usage:</strong> Use tools like kubectl top to monitor the memory usage of the MySQL container.</p>
<p><strong>Logs:</strong> Examine the MySQL container logs more thoroughly. Apart from the log snippet you provided, look for any error messages or warnings in the MySQL error log.</p>
<p><strong>Check Persistent Volume:</strong> Ensure that the PersistentVolume (PV) and PersistentVolumeClaim (PVC) are correctly set up. You might need to delete and recreate the PVC.</p>
<p><strong>Database Initialization:</strong> If the MySQL database initialization is failing, it could cause the container to crash. Check if the initialization script is executing correctly.</p>
<p><strong>Check for External Factors:</strong> If the host machine where Minikube is running has resource constraints or issues, it could affect the containers. Make sure the host machine has enough resources.</p>
