Does MySQL Work With Kubernetes?
MySQL works excellently with Kubernetes through containerization and StatefulSets, enabling production-grade database deployments on K8s clusters.
Quick Facts
How MySQL Works With Kubernetes
MySQL runs seamlessly on Kubernetes by containerizing the database in Docker and managing it through StatefulSets, which provide stable network identities and persistent storage—critical for databases. Kubernetes handles orchestration, scaling, and self-healing, while PersistentVolumes ensure data survives pod restarts. The typical developer experience involves deploying MySQL via Helm charts (like Bitnami's official chart) or writing custom StatefulSet manifests, configuring PersistentVolumeClaims for storage, and exposing the database via Services. The main architectural consideration is choosing between single-instance setups for development and multi-replica configurations with replication for production high-availability. Kubernetes's init containers can handle schema initialization, and Jobs can manage backups. Most teams use managed options like Google Cloud SQL or AWS RDS for production rather than self-hosted K8s MySQL due to operational overhead, but on-cluster deployment works well for dev/test environments and specific workloads.
Best Use Cases
Deploy MySQL on Kubernetes with StatefulSet
helm repo add bitnami https://charts.bitnami.com/bitnami && helm repo update# Install MySQL via Helm (recommended)
helm install mysql bitnami/mysql \
--set auth.rootPassword=secretpassword \
--set primary.persistence.size=10Gi
# Or deploy custom StatefulSet
cat <<EOF | kubectl apply -f -
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: mysql
spec:
serviceName: mysql
replicas: 1
selector:
matchLabels:
app: mysql
template:
metadata:
labels:
app: mysql
spec:
containers:
- name: mysql
image: mysql:8.0
env:
- name: MYSQL_ROOT_PASSWORD
value: "rootpass"
ports:
- containerPort: 3306
volumeMounts:
- name: data
mountPath: /var/lib/mysql
volumeClaimTemplates:
- metadata:
name: data
spec:
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 10Gi
---
apiVersion: v1
kind: Service
metadata:
name: mysql
spec:
clusterIP: None
selector:
app: mysql
ports:
- port: 3306
targetPort: 3306
EOF
# Connect from pod
kubectl run -it --rm mysql-client --image=mysql:8.0 -- \
mysql -h mysql -u root -prootpassKnown Issues & Gotchas
Data loss if PersistentVolume backend fails without replication configured
Fix: Always use PersistentVolumes backed by redundant storage (cloud provider managed storage), implement MySQL replication, or use managed database services
StatefulSet scaling is not automatic; manual replica configuration required for HA
Fix: Use Helm charts with built-in replication templates, or implement MySQL Operator for automated failover and scaling
Network policies and Service DNS can cause connection timeouts if not properly configured
Fix: Verify Service DNS names, check NetworkPolicies allow traffic, use headless Services for StatefulSets
Performance degradation from container resource limits if not sized appropriately
Fix: Set appropriate CPU/memory requests and limits based on workload, monitor with Prometheus/Grafana
Alternatives
- •PostgreSQL with Kubernetes + Helm/CloudNativePG operator (better ACID compliance, superior K8s integration)
- •AWS RDS + EKS (fully managed database removes operational burden)
- •MongoDB with Kubernetes (document-oriented, better horizontal scaling patterns)
Resources
Related Compatibility Guides
Explore more compatibility guides