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正常,问题解决
相关推荐
蜕变的土豆1 小时前
ubuntu22.04下安装mysql以及mysql-workbench
数据库·mysql
东风微鸣1 小时前
Grafana将弃用AngularJS-我们该如何迁移
docker·云原生·kubernetes·可观察性
BUG 劝退师3 小时前
MySQL数据库编程总结
数据库·mysql
开心码农1号3 小时前
当一个 HTTP 请求发往 Kubernetes(K8s)部署的微服务时,整个过程流转时怎样的?
http·微服务·kubernetes
Linux运维老纪4 小时前
GitLab之搭建(Building GitLab)
linux·mysql·云计算·gitlab·运维开发
老李不敲代码4 小时前
榕壹云在线商城系统:基于THinkPHP+ Mysql+UniApp全端适配、高效部署的电商解决方案
mysql·微信小程序·小程序·uni-app·软件需求
嘉嘉king5 小时前
Mysql中的数据类型和语句概述
数据库·mysql
仰望星空的小随5 小时前
mysql相关面试题
数据库·mysql
云攀登者-望正茂6 小时前
通过AWS EKS 生成并部署容器化应用
云原生·kubernetes·aws
kennygu7 小时前
jenkins项目发布-安装k8s(rancher)客户端kubectl
kubernetes·jenkins·rancher