AWS环境中挂载存储卷的Kubernetes MySQL Pod运行失败求助
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:
If the status iskubectl get pvc mysql-pv-claimPending, 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
AmazonEBSCSIDriverPolicyattached.
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

