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


    前言

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

    部署mysql

    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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87

    报错

    #创建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 ~]#
    
    • 1
    • 2
    • 3
    • 4
    • 5

    解决办法

    #测试使用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正常,问题解决
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
  • 相关阅读:
    关于蓝牙人员定位的几个重要问题
    构建实时视频聊天应用:使用WebRTC和Netty的完整指南
    使用Docker部署debezium来监控MySQL数据库
    关于红包雨功能的探索
    会议项目之审批
    nacos安装与配置
    ThinkPHP5校园图书馆管理系统
    Cobalt Strike 的 Beacon 使用介绍以及 Profile 文件修改Beacon内存教程
    零基础5分钟上手亚马逊云科技AWS核心云架构知识 - 为应用配置自动扩展
    「尚硅谷与腾讯云官方合作」硅谷课堂项目视频发布
  • 原文地址:https://blog.csdn.net/MssGuo/article/details/133580346