k8s部署mysql报错‘/var/lib/mysql/‘: Operation not permitted

前言

环境:k8s 1.22.6、nfs-server后端存储

部署mysql

bash 复制代码
kind: StatefulSet
apiVersion: apps/v1
metadata:
  name: mysql-his
  namespace: his
  labels:
    app: mysql-his
  annotations:
    kubesphere.io/alias-name: mysql-his
    kubesphere.io/creator: dev-liu
    kubesphere.io/description: his项目的数据库
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mysql-his
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: mysql-his
      annotations:
        kubesphere.io/creator: dev-liu
        kubesphere.io/imagepullsecrets: '{}'
        logging.kubesphere.io/logsidecar-config: '{}'
    spec:
      volumes:
        - name: host-time
          hostPath:
            path: /etc/localtime
            type: ''
      containers:
        - name: container-91dh9a
          image: 'mysql:5.7.35'
          ports:
            - name: tcp-3306
              containerPort: 3306
              protocol: TCP
            - name: tcp-33060
              containerPort: 33060
              protocol: TCP
          env:
            - name: MYSQL_ROOT_PASSWORD
              value: Aa123456
          resources: {}
          volumeMounts:
            - name: host-time
              mountPath: /etc/localtime
            - name: mysql-his
              mountPath: /var/lib/mysql
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
          imagePullPolicy: IfNotPresent
          securityContext:
            privileged: true
      restartPolicy: Always
      terminationGracePeriodSeconds: 30
      dnsPolicy: ClusterFirst
      serviceAccountName: default
      serviceAccount: default
      securityContext:
        runAsNonRoot: false
      schedulerName: default-scheduler
  volumeClaimTemplates:
    - kind: PersistentVolumeClaim
      apiVersion: v1
      metadata:
        name: mysql-his
        namespace: his
        creationTimestamp: null
      spec:
        accessModes:
          - ReadWriteOnce
        resources:
          requests:
            storage: 1Gi
        storageClassName: nfs-storageclass
        volumeMode: Filesystem
      status:
        phase: Pending
  serviceName: mysql-his-6kpe
  podManagementPolicy: OrderedReady
  updateStrategy:
    type: RollingUpdate
    rollingUpdate:
      partition: 0
  revisionHistoryLimit: 10

报错

bash 复制代码
#创建sts之后,pod启动报错,日志如下
[root@master01 ~]# kubectl  -n his  logs   mysql-his-0 
2023-10-05 15:41:02+08:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.35-1debian10 started.
chown: changing ownership of '/var/lib/mysql/': Operation not permitted
[root@master01 ~]#

解决办法

bash 复制代码
#测试使用docker启动mysql,可以正常启动
mysql -p  /my/own/datadir
docker run --name mysql -v /my/own/datadir:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=Aa123456 -d mysql:5.7.35

#最后问题定位为后端存储nfs配置存在错误。
#查看nfs配置:
[root@master01 k8s]# cat /etc/exports
/data/k8s *(rw,sync)
#添加一个参数:
[root@master01 k8s]# cat /etc/exports
/data/k8s *(rw,sync,no_root_squash)
[root@master01 k8s]# exportfs -rv	#使配置立即生效,也可以systemctl reload nfs-server.service
#最后重新创建mysql pod,pod正常,问题解决
相关推荐
AKA小徐37 分钟前
Debian12使用RKE2离线部署3master2node三主两从的k8s集群详细教程
kubernetes·rancher·rke2
夜半被帅醒1 小时前
MySQL 数据库优化详解【Java数据库调优】
java·数据库·mysql
不爱学习的啊Biao1 小时前
【13】MySQL如何选择合适的索引?
android·数据库·mysql
Rverdoser1 小时前
MySQL-MVCC(多版本并发控制)
数据库·mysql
醒了就刷牙2 小时前
黑马Java面试教程_P9_MySQL
java·mysql·面试
橘子师兄5 小时前
如何在自己的云服务器上部署mysql
运维·服务器·mysql
core5126 小时前
flink sink doris
大数据·mysql·flink·doris·存储·sink·过程正常
苹果酱05677 小时前
「Mysql优化大师一」mysql服务性能剖析工具
java·vue.js·spring boot·mysql·课程设计
Minxinbb7 小时前
MySQL中Performance Schema库的详解(上)
数据库·mysql·dba
滚雪球~7 小时前
2002 - Can‘t connect to server on ‘192.168.1.XX‘ (36)
mysql·navicat