You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

AWS环境中挂载存储卷的Kubernetes MySQL Pod运行失败求助

Troubleshooting MySQL Pod Failure in AWS Kubernetes

Let’s walk through the key steps to diagnose and fix why your MySQL pod is failing to run in your AWS Kubernetes environment:

1. Start with Pod Status and Logs

First, gather direct clues about the failure by checking the pod’s state and logs:

  • List all pods in your namespace to identify the failing MySQL pod:
    kubectl get pods
    
  • Describe the pod to view critical events (like volume mount failures, image pull errors, or permission issues):
    kubectl describe pod mysql-<your-pod-id>
    
  • Check MySQL-specific logs to see if the database itself is throwing errors on startup:
    kubectl logs mysql-<your-pod-id>
    

2. Verify PVC Binding Status

In AWS, Kubernetes uses EBS volumes for ReadWriteOnce PVCs by default. Ensure your PVC is properly bound to a Persistent Volume (PV):

  • Check the PVC status:
    kubectl get pvc mysql-pv-claim
    
    If the status is Pending, common causes include:
    • No EBS volumes available matching your 20Gi storage request and access mode.
    • Missing IAM permissions on your EKS node role to create/attach EBS volumes. Ensure the role has the AmazonEBSCSIDriverPolicy attached.

3. Fix the Missing Volume Mount Configuration

Looking at your provided YAML, the Deployment is missing critical volume mount settings—Kubernetes can’t know to attach your PVC to /var/lib/mysql without this. Add these sections to your Deployment’s spec.template.spec:

volumes:
- name: mysql-storage
  persistentVolumeClaim:
    claimName: mysql-pv-claim
containers:
- image: mysql:5.6
  name: mysql
  # ... keep your existing env, ports, etc.
  volumeMounts:
  - name: mysql-storage
    mountPath: /var/lib/mysql

4. Resolve File Permission Issues

MySQL requires the /var/lib/mysql directory to be owned by the mysql user (UID 999 for the mysql:5.6 image). If your EBS volume has incorrect permissions, the database will fail to start. Fix this with an init container:

initContainers:
- name: init-mysql
  image: mysql:5.6
  command: ["chown", "-R", "999:999", "/var/lib/mysql"]
  volumeMounts:
  - name: mysql-storage
    mountPath: /var/lib/mysql

Add this right above your main containers section in the Deployment.

5. Validate EBS CSI Driver Installation

For EKS 1.23+, the legacy in-tree EBS driver is deprecated—you need the EBS CSI Driver installed. Verify it’s running:

kubectl get pods -n kube-system -l app=ebs-csi-controller

If it’s missing, deploy it using eksctl or Helm (AWS provides official deployment methods for this driver).

6. Complete Your Truncated YAML

Your provided Deployment cuts off at the ports section. Make sure you include the full port configuration:

ports:
- containerPort: 3306
  name: mysql

After addressing these points, redeploy your configuration:

kubectl apply -f your-mysql-manifest.yaml

内容的提问来源于stack exchange,提问作者Ravichandra

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 04:07:58