Running WordPress on a single server works fine for small sites. But when you need high availability, scalability, and containerized flexibility, Kubernetes (K8s) is the way forward.
With Kubernetes, you can deploy WordPress across multiple containers, connect it to a MySQL or MariaDB database, and scale horizontally with ease.
In this guide, we’ll walk through how to deploy WordPress on Kubernetes, covering setup, configuration, and best practices.
Contents
Why Use Kubernetes for WordPress?
-
⚡ Scalability – Easily add more replicas during traffic spikes.
-
🔒 Isolation – Containers separate app, database, and services.
-
🚀 Portability – Run WordPress anywhere (AWS, GCP, Azure, on-premise).
-
🔄 Auto-healing – Kubernetes restarts failed pods automatically.
-
💰 Efficient Resource Usage – Manage CPU and memory limits.
Step 1: Prepare Kubernetes Cluster
You can run Kubernetes on:
-
Minikube (local testing).
-
Managed K8s: Amazon EKS, Google GKE, or Azure AKS.
For local testing:
Step 2: Deploy MySQL (or MariaDB)
Create a mysql-deployment.yaml
:
Then expose it with a service:
Step 3: Deploy WordPress
Create a wordpress-deployment.yaml
:
Expose WordPress service:
Check services:
You’ll see a NodePort assigned (e.g., 30080
). Access WordPress at http://<minikube-ip>:30080
.
Step 4: Persistent Storage
For production, you should attach Persistent Volume (PV) and Persistent Volume Claim (PVC) to store:
-
WordPress uploads
-
Database data
Example pvc.yaml
:
Step 5: Ingress + Domain Setup
-
Install NGINX Ingress Controller:
-
Create an Ingress resource to map domain to WordPress service.
-
Update your
/etc/hosts
to pointmywordpress.local
to Minikube IP.
Step 6: Scaling WordPress Pods
To scale WordPress containers:
Kubernetes will automatically distribute traffic across all pods.
Best Practices
-
Use Secrets for database credentials.
-
Enable Horizontal Pod Autoscaler (HPA) for automatic scaling.
-
Use ConfigMaps for WordPress configuration.
-
Implement TLS certificates with Let’s Encrypt + Cert-Manager.
-
Use Helm charts for production-ready WordPress deployments.
FAQ
1. Can I run WooCommerce on Kubernetes?
Yes, but you’ll need persistent volumes and caching for performance.
2. Is Kubernetes overkill for small blogs?
Yes. Kubernetes is best for enterprise or high-traffic WordPress sites.
3. Which cloud provider is best for WordPress Kubernetes?
AWS (EKS), GCP (GKE), and Azure (AKS) all work. Choose based on your existing cloud usage.
4. Can I migrate an existing WordPress site to Kubernetes?
Yes. Export your DB and media files, then import into your K8s-based WordPress.
5. How do I handle backups?
Use Velero for cluster backups and regular database dumps.