<p>When I start my mysql 5.7 pods in kubernetes v1.15.2, the logs shows like this:</p>

<pre><code>2020-05-30 13:08:04+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.30-1debian10 started.
chown: changing ownership of '/var/lib/mysql/': Operation not permitted
</code></pre>

<p>this is my mysql yaml define:</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: apollo-mysql
  namespace: sre
spec:
  ports:
  - port: 3306
  selector:
    app: mysql
  clusterIP: None
---
apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
  name: apollo-mysql
  namespace: sre
spec:
  selector:
    matchLabels:
      app: apollo-mysql
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: apollo-mysql
    spec:
      containers:
      - image: mysql:5.7
        name: mysql
        env:
          # Use secret in real usage
        - name: MYSQL_ROOT_PASSWORD
          value: gfwge4LucnXwfefewegLwAd29QqJn4
        ports:
        - containerPort: 3306
          name: mysql
        volumeMounts:
        - name: apollo-mysql-persistent-storage
          mountPath: /var/lib/mysql
      volumes:
      - name: apollo-mysql-persistent-storage
        persistentVolumeClaim:
          claimName: apollo-mysql-pv-claim
</code></pre>

<p>and this is my pv define:</p>

<pre><code>apiVersion: v1
kind: PersistentVolume
metadata:
  name: nfs-apollo-mysql-pv1
  namespace: sre
  labels:
    alicloud-pvname: apollo-mysql-data-db
spec:
  capacity:
    storage: 5Gi
  storageClassName: apollo-mysql-data-db
  mountOptions:
    - vers=4.0
    - noresvport
  accessModes:
    - ReadWriteOnce
  nfs:
    server: "192.168.64.237"
    path: "/mnt/data/apollodb/apollopv"
  persistentVolumeReclaimPolicy: Retain
</code></pre>

<p>and I already change the mod to 777 like this:</p>

<pre><code>chmod 777 /mnt/data/apollodb/apollopv
</code></pre>

<p>so where is the problem and what should I do to fix this? I check the selinux status and it is disabled.</p>

<pre><code>[miao@meowk8sslave3 apollodb]$ /usr/sbin/sestatus -v
SELinux status:                 disabled
</code></pre>

<p>This is my nfs exports define:</p>

<pre><code>/mnt/data/apollodb/apollopv *(rw,sync,no_subtree_check,no_root_squash)
</code></pre>

<p>The yaml you have provided is missing PVC, which specifies the <code>storageClass</code> to be mounted.</p>

<p>It looks like you are trying to mount an external NFS (with some cloud provider perhaps), in which case you need to have <code>nfs-utils</code> installed, and do <code>mount -t nfs 192.168.64.237:/entrypoint /mnt/...</code>.</p>

<p>Your PV says <code>/mnt/data/apollodb/apollopv</code>, which should be the entrypoint to the nfs server, and not where it is going to be mounted in your filesystem. </p>

<p>To make this work, get yourself an nfs server (get the IP address and the entrypoint; say 192.168.64.237:/nfs), then mount it in your pod as follows:</p>

<pre><code>apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
  name: apollo-mysql
  namespace: sre
spec:
  selector:
    matchLabels:
      app: apollo-mysql
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: apollo-mysql
    spec:
      containers:
      - image: mysql:5.7
        name: mysql
        env:
          # Use secret in real usage
        - name: MYSQL_ROOT_PASSWORD
          value: gfwge4LucnXwfefewegLwAd29QqJn4
        ports:
        - containerPort: 3306
          name: mysql
        volumeMounts:
        - name: apollo-mysql-persistent-storage
          mountPath: /var/lib/mysql
      volumes:
      - name: apollo-mysql-persistent-storage
        nfs:
          server: 192.168.64.237
          path: "/nfs"
</code></pre>

<p>You won't need the storage class, the PVC and the PV. Everything you need is in the pod, and externally you have the nfs server.</p>
