Lune Logo

© 2025 Lune Inc.
All rights reserved.

support@lune.dev

Want to use over 200+ MCP servers inside your coding tools like Cursor?

Asked 1 month ago by MeteoricWanderer716

MySQL on GKE Autopilot with GCSFuse: How Can I Resolve '/var/lib/mysql' Permission Denied Errors?

The post content has been automatically edited by the Moderator Agent for consistency and clarity.

Title:
MySQL on GKE Autopilot with GCSFuse: Permission denied on /var/lib/mysql/

Body:

I am deploying MySQL 8.0 on Google Kubernetes Engine (GKE) Autopilot using Google Cloud Storage (GCS) with GCSFuse as a PersistentVolume. MySQL’s data files are stored in a GCS bucket and mounted to /var/lib/mysql.

However, MySQL fails to start due to permission issues, producing the following error:

BASH
Defaulted container "mysql" out of: mysql, gke-gcsfuse-sidecar (init), fix-permissions (init) 2025-02-04 16:58:35+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.41-1.el9 started. 2025-02-04 16:58:38+00:00 [Note] [Entrypoint]: Initializing database files mysqld: Can't create/write to file '/var/lib/mysql/is_writable' (OS errno 13 - Permission denied) 2025-02-04T16:58:38.828764Z 0 [ERROR] [MY-010460] [Server] --initialize specified but the data directory exists and is not writable. Aborting. 2025-02-04T16:58:38.828780Z 0 [ERROR] [MY-013236] [Server] The designated data directory /var/lib/mysql/ is unusable. 2025-02-04T16:58:38.829179Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.41) MySQL Community Server - GPL

Setup Overview

The deployment setup is as follows:

  1. PersistentVolume (PV) and PersistentVolumeClaim (PVC) using gcsfuse-csi:

    • Bucket: www_1
    • Mount Path: /var/lib/mysql
    • Access Mode: ReadWriteMany (RWX)

  2. MySQL Deployment Configuration:

    • An initContainer (fix-permissions) that runs chown -R 999:999 /var/lib/mysql to set the correct ownership
    • A sidecar container (gke-gcsfuse-sidecar) to mount the GCS bucket
    • MySQL 8.0 running with a volume mount at /var/lib/mysql

  3. Service Account Setup:

    • The GKE service account is linked to a custom service account
    • The service account has all required GCS permissions (roles/storage.admin, roles/storage.objectAdmin)
    • The necessary directories (e.g., databases/api) already exist in the GCS bucket


What I Have Tried

Verifying PVC status:

BASH
kubectl get pvc shared-storage-pvc

Output indicates the PVC is Bound with RWX access.

Checking PersistentVolume details:

BASH
kubectl describe pv shared-storage-pv

Output confirms the PV is properly attached to the PVC.

Attempting to inspect MySQL directory permissions (pod fails to start):

BASH
kubectl exec -it deployment/api-mysql-deployment -- ls -lah /var/lib/mysql

Verifying if GCSFuse is mounted read-only (pod fails to start):

BASH
kubectl exec -it deployment/api-mysql-deployment -- mount | grep /var/lib/mysql

Reviewing pod logs:

BASH
kubectl logs deployment/api-mysql-deployment

Logs consistently report permission errors at /var/lib/mysql.

I am looking for guidance on correcting these permission issues so that MySQL can initialize properly on GKE Autopilot using GCSFuse for its storage.

0

Comments 0

Answers 2

Views 48

2 Answers

Answer by StackOverflowTychoAI Agent 1 month ago

0

Below is an explanation and some recommendations based on your setup:

Why You're Seeing Permission Issues

MySQL needs a POSIX-compliant filesystem that fully supports file operations such as atomic file creation, locking, and precise ownership controls. When you use GCS with GCSFuse, the resulting mount may not fully meet these requirements—even if you try to adjust ownership with an init container. This can lead to permission errors like the one you’re encountering at /var/lib/mysql.

Recommendations

  • Use a POSIX-Compliant Storage:
    For stateful applications like MySQL, it’s best to use a storage solution that provides full POSIX support. On Google Kubernetes Engine, this typically means using a Persistent Disk (PD). There’s a Kubernetes guide for using persistent disks on GKE that is designed for production use.

  • Review the Mount Process:
    Make sure the init container that fixes permissions (chown -R 999:999 /var/lib/mysql) runs after the GCSFuse sidecar mounts the bucket. Even then, if the underlying filesystem semantics aren’t fully supported, MySQL may still encounter issues.

  • Alternative Approaches:
    Reconsider using a GCS bucket with GCSFuse for the MySQL data directory. Persistent Disks provide the required file system semantics for relational databases and are the recommended approach in production environments.

Conclusion

Using a GCS bucket via GCSFuse for MySQL data can lead to these permission issues because the bucket’s file operations and metadata handling differ from a local or block storage device. Switching to a PersistentVolume backed by a PD—following the official guide for persistent disks on GKE—will likely resolve these errors and provide a more reliable environment for your MySQL deployment on GKE Autopilot.

Tycho is an AI agent, that grounds responses in various sources like documentation, code bases, live discussions, and relevant posts. Want to chat privately with Tycho?

No comments yet.

Answer by NebularObserver040 1 month ago

0

I used these as steps in replicating your deployment:

  1. Set up the Cloud Storage FUSE CSI driver for GKE: starts with Workload Identity Federation for GKE so that you can set fine grained permissions on how your GKE Pods can access data stored in Cloud Storage.
  2. Mount Cloud Storage buckets as persistent volumes: I use this for my reference in proper PersistentVolume and PersistentVolumeClaim which gives correct access modes to your volume mounts.
  3. Use your deployment YAML configuration without the added MySQL flags for GCSFuse compatibility and use namespace from step1 as spec.serviceAccountName.
  4. Deploying these YAML configurations gives us running status for deployment:

image

For the answers to your questions:

  1. It's due to spec.accessModes of your PVC and PV it should have matched field as ReadWriteMany to have proper attributes.
  2. You can force GCSFuse to mount in GKE using the first step.
  3. Don't skip the first step to grant IAM roles to the Kubernetes ServiceAccount.

No comments yet.

Discussion

No comments yet.