BS问题:k8s部署 mysql chown: changing ownership of ‘/var/lib/mysql‘: Operation not permitted


apiVersion: v1
kind: ReplicationController
metadata:
  name: mysql
  labels:
    name: mysql
spec:
  replicas: 1
  selector:
    name: mysql
  template:
    metadata:
      labels:
        name: mysql
    spec:
      containers:
      - name: mysql
        image: mysql:8.0
        securityContext:
          runAsUser: 1000 
          allowPrivilegeEscalation: false
        ports:
        - containerPort: 3306
        volumeMounts:
        - name: mysql-data
          mountPath: /var/lib/mysql
        env:
        - name: MYSQL_ROOT_PASSWORD
          value: "root"
        - name: MYSQL_DATABASE
          value: "nacos_devtest"
        - name: MYSQL_USER
          value: "nacos"
        - name: MYSQL_PASSWORD
          value: "nacos"
      volumes:
      - name: mysql-data
        nfs:
          server: 192.168.3.51
          path: /data/mysql
---
apiVersion: v1
kind: Service
metadata:
  name: mysql
  labels:
    name: mysql
spec:
  ports:
  - port: 3306
    targetPort: 3306
  selector:
    name: mysql

尝试一、添加  no_root_squash

cat /etc/exports
/data/nfs-share 192.168.3.0/16(rw,sync,all_squash,anonuid=1000,anongid=1000)
/data/mysql 192.168.3.0/16(rw,sync,all_squash,anonuid=1000,anongid=1000,no_root_squash)

这个对我来说不起作用

尝试二、

在yaml文件中添加这个:

securityContext:
          runAsUser: 1000 
          allowPrivilegeEscalation: false

运行成功

[root@m mysql]# kubectl get pods 
NAME                                     READY   STATUS    RESTARTS   AGE
h5-fallback-c7b88d658-8gwn8              1/1     Running   4          7d18h
mysql-r84s6                              1/1     Running   0          5m14s
nfs-client-provisioner-8f7d9db6b-sncm7   1/1     Running   0          103m

你可能感兴趣的:(mysql,kubernetes,数据库)