KubeKanvas Logo
  • Features
  • Pricing
  • Templates
    • How KubeKanvas works
    • Docs
    • Downloads
    • Blog
    • E-Book
    • Tutorials
  • FAQs
  • Contact
  • Features
  • Pricing
  • Templates
    • How KubeKanvas works
    • Docs
    • Downloads
    • Blog
    • E-Book
    • Tutorials
  • FAQs
  • Contact
Back to Templates

Deploy MySQL on Kubernetes with Backup: StatefulSet Template

Tags:
#MySQL#StatefulSet#CronJob#BackupAndRecovery
Created by:
Mahmood
Deploy MySQL on Kubernetes with Backup: StatefulSet Template template preview
0 uses
KubeKanvas Logo
Visual Kubernetes cluster design tool that helps you create, manage, and deploy your applications with ease.
Product
  • Features
  • Pricing
  • Templates
Resources
  • Blog
  • Tutorials
Company
  • About Us
  • Contact
  • Terms of Service
  • Privacy Policy
  • Impressum
XGitHubLinkedIn
© 2026 KubeKanvas. All rights reserved.

Running MySQL on Kubernetes as a standard Deployment does not guarantee stable pod identity or ordered lifecycle management, which can lead to data inconsistency and storage reattachment failures. This template deploys MySQL 8.0 as a StatefulSet with VolumeClaimTemplates, a headless Service for stable DNS, a ClusterIP Service for load-balanced connections, a non-root security context, externalized credentials, and a scheduled backup CronJob.

What's Included

ComponentTypePortRole
MySQL 8.0StatefulSet3306Primary database with stable pod identity and ordered lifecycle
PVC (via VolumeClaimTemplates)PersistentVolumeClaim-Automatically provisioned persistent storage per pod
Headless ServiceService-Stable DNS for direct pod addressing (mysql-0.mysql-headless)
ClusterIP ServiceService3306Load-balanced access for standard database connections
ConfigMapConfigMap-Non-sensitive database name configuration
SecretSecret-MySQL credentials injected at runtime
Backup CronJobCronJob-Scheduled database backups

Architecture Overview

MySQL 8.0 runs as a StatefulSet with VolumeClaimTemplates that automatically provision a PVC per pod. A headless Service provides stable DNS addresses (mysql-0.mysql-headless.default.svc.cluster.local) for clients that require a direct connection to a specific pod. A standard ClusterIP Service handles load-balanced traffic for general database clients. The ConfigMap stores the database name and the Secret injects credentials at runtime. A SecurityContext enforces non-root execution at UID 1001. A CronJob handles scheduled backups.

Prerequisites

  • A running Kubernetes cluster
  • Storage class configured for dynamic PVC provisioning
  • KubeKanvas CLI installed and running on your computer (Optional, if you want to use one-click deployment)

How to Deploy

  1. Click Use Template to load the manifest into the editor.
  2. Update the ConfigMap with your database name.
  3. Replace the credential placeholders in the Secret with your base64-encoded MySQL username and password.
  4. Confirm the storage class in the VolumeClaimTemplates matches what is available in your cluster.
  5. Deploy the template to your cluster via the Play button in the top right bar. If you prefer to deploy manually, download the YAML and apply it with kubectl.
  6. Wait for all pods to reach Running status. You can monitor progress in the Release Monitor screen.

How to Test

  1. Confirm the StatefulSet pod is running and the PVC is bound: kubectl get pods,pvc -n <namespace>.
  2. Open a MySQL shell on the pod: kubectl exec -it mysql-0 -n <namespace> -- mysql -u <username> -p.
  3. Run SHOW DATABASES; to confirm your configured database is listed.
  4. Run SELECT VERSION(); to verify MySQL 8.0 is running.

Use Cases

  • Stateful MySQL workloads: Replacing a MySQL Deployment with a StatefulSet for guaranteed stable pod naming and reliable PVC reattachment across restarts.
  • Dual-access database setup: Applications that need both direct pod addressing via the headless Service and load-balanced access via the ClusterIP Service simultaneously.
  • Backup-enabled database deployment: Running MySQL on Kubernetes with automated CronJob backups built in from day one.
  • Non-root database containers: Environments that require all database processes to run as a non-root user as part of a security policy.

Summary

This template configures a MySQL 8.0 StatefulSet on Kubernetes with automatic persistent storage, dual-service networking, a non-root security context, externalized credentials, and scheduled backups.