k8s部署mysql5.7报错CrashLoopBackOff?

k8s部署mysql5.7报错CrashLoopBackOff,

一、查询日志:
kubectl describe pod mysql-deployment-6557b4b9df-5tglp

ame:             mysql-deployment-6557b4b9df-5tglp
Namespace:        default
Priority:         0
Service Account:  default
Node:             k8s-worker/10.8.91.179
Start Time:       Tue, 15 Oct 2024 17:34:24 +0800
Labels:           app=mysql
                  pod-template-hash=6557b4b9df
Annotations:      cni.projectcalico.org/containerID: 13183c4d3e208eb99551ceadaed9eaf90d122457daf34c9855699b1d5ecde548
                  cni.projectcalico.org/podIP: 192.168.254.129/32
                  cni.projectcalico.org/podIPs: 192.168.254.129/32
Status:           Running
IP:               192.168.254.129
IPs:
  IP:           192.168.254.129
Controlled By:  ReplicaSet/mysql-deployment-6557b4b9df
Containers:
  mysql:
    Container ID:   docker://38fe887a99075ccda7a3618ffb2eebb3fdba7f4e51db1c93cffabc7ef6eb47fc
    Image:          mysql:5.7
    Image ID:       docker-pullable://mysql@sha256:4bc6bc963e6d8443453676cae56536f4b8156d78bae03c0145cbe47c2aad73bb
    Port:           3306/TCP
    Host Port:      0/TCP
    State:          Waiting
      Reason:       CrashLoopBackOff
    Last State:     Terminated
      Reason:       OOMKilled
      Exit Code:    1
      Started:      Tue, 15 Oct 2024 18:32:20 +0800
      Finished:     Tue, 15 Oct 2024 18:32:23 +0800
    Ready:          False
    Restart Count:  16
    Environment:
      MYSQL_ROOT_PASSWORD:  root
    Mounts:
      /var/lib/mysql from mysql-storage (rw)
      /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-77zzt (ro)
Conditions:
  Type              Status
  Initialized       True
  Ready             False
  ContainersReady   False
  PodScheduled      True
Volumes:
  mysql-storage:
    Type:       PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
    ClaimName:  mysql-pvc
    ReadOnly:   false
  kube-api-access-77zzt:
    Type:                    Projected (a volume that contains injected data from multiple sources)
    TokenExpirationSeconds:  3607
    ConfigMapName:           kube-root-ca.crt
    ConfigMapOptional:       <nil>
    DownwardAPI:             true
QoS Class:                   BestEffort
Node-Selectors:              <none>
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   Pulled   59m (x5 over 61m)    kubelet  Container image "mysql:5.7" already present on machine
  Normal   Created  59m (x5 over 61m)    kubelet  Created container mysql
  Normal   Started  59m (x5 over 61m)    kubelet  Started container mysql
  Warning  BackOff  94s (x274 over 61m)  kubelet  Back-off restarting failed container mysql in pod mysql-deployment-6557b4b9df-5tglp_default(7bbe3372-f8e8-4f7d-bd16-c994214d350c)

二、pod的log日志:
kubectl logs mysql-deployment-6557b4b9df-5tglp

2024-10-15 11:08:22+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.44-1.el7 started.
2024-10-15 11:08:25+00:00 [ERROR] [Entrypoint]: mysqld failed while attempting to check config,command was: mysqld --verbose --help --log-bin-index=/tmp/tmp.QWaOpkicxB

系统centos7.9
kubectl ,kubelet,kudoam version都是1.28.0

查了stackoverslow等,试了各种办法还是报错;

***delyments.yaml***
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mysql-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mysql
  template:
    metadata:
      labels:
        app: mysql
    spec:
      containers:
      - name: mysql
        image: mysql:5.7
        env:
        - name: MYSQL_ROOT_PASSWORD
          value: root
        ports:
        - containerPort: 3306
        volumeMounts:
        - mountPath: /var/lib/mysql
          name: mysql-storage
      volumes:
      - name: mysql-storage
        persistentVolumeClaim:
          claimName: mysql-pvc

persistentVolume.yaml

apiVersion: v1
kind: PersistentVolume
metadata:
  name: mysql-pv
spec:
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: /var/lib/mysqlyaml/mysqlvolume

persistentVolumeClaim.yaml

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mysql-pvc
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi

这是目前所有的pod

root@k8s-master mysqlyaml]# kubectl get pods -A
NAMESPACE     NAME                                      READY   STATUS             RESTARTS        AGE
default       mysql-deployment-6557b4b9df-m6xch         0/1     CrashLoopBackOff   8 (3m30s ago)   19m
kube-system   calico-kube-controllers-8d76c5f9b-9xpf9   1/1     Running            0               24m
kube-system   calico-node-gbxkq                         1/1     Running            0               29m
kube-system   calico-node-rfmx5                         1/1     Running            0               27m
kube-system   coredns-66f779496c-nbhvw                  1/1     Running            0               24m
kube-system   coredns-66f779496c-vrmlf                  1/1     Running            0               24m
kube-system   etcd-k8s-master                           1/1     Running            5               29m
kube-system   kube-apiserver-k8s-master                 1/1     Running            0               29m
kube-system   kube-controller-manager-k8s-master        1/1     Running            0               29m
kube-system   kube-proxy-729xf                          1/1     Running            0               27m
kube-system   kube-proxy-wshzk                          1/1     Running            0               29m
阅读 1.6k
2 个回答

可以贴一下配置文件,还有部署的时候用到的yaml文件。

本地随便写了个yaml测试了一下,启动是没啥问题的。

看了一下启动脚本,根据你提供的报错信息是在这一步卡住了。执行mysql_check_config时,这里抛出了异常,所以你应该检查一下配置文件。
image.png

这里 mysql_error 执行后,就退出了。
image.png

你pod log 应该还有错误日志,麻烦全部展示出来

***delyments.yaml***
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mysql-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mysql
  template:
    metadata:
      labels:
        app: mysql
    spec:
      containers:
      - name: mysql
        image: mysql:5.7
        env:
        - name: MYSQL_ROOT_PASSWORD
          value: root
        ports:
        - containerPort: 3306

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
宣传栏