How to Deploy WordPress on Kubernetes (Step-by-Step Guide)

Kubernetes has become the standard platform for deploying and managing containerized applications at scale. While many beginners first use Kubernetes for simple test applications, deploying a real-world CMS like WordPress is one of the best practical ways to understand how Kubernetes works.
If you want to combine the flexibility of WordPress with the scalability and automation of Kubernetes, this guide will walk you through the entire process.
In this tutorial, you will learn how to deploy WordPress on Kubernetes step by step, including setting up persistent storage, MySQL database, deployments, services, and exposing your WordPress site to the internet.
Why Deploy WordPress on Kubernetes?
Before jumping into setup, let’s understand why someone would run WordPress on Kubernetes.
Main Benefits
- Automatic scaling during traffic spikes
- Self-healing if containers fail
- High availability across nodes
- Better resource utilization
- Easier CI/CD integration
When It Makes Sense
Deploying WordPress on Kubernetes is ideal when:
- You manage multiple WordPress websites
- You need enterprise-level uptime
- You expect high traffic
- You want DevOps automation
Prerequisites
Before starting, make sure you have:
- A working Kubernetes cluster
- kubectl installed
- Basic Docker/Kubernetes knowledge
- Domain name (optional)
- Load balancer or ingress controller
Kubernetes Components Needed for WordPress
To deploy WordPress properly, we need:
- MySQL Deployment
- MySQL Persistent Volume
- WordPress Deployment
- WordPress Service
- Persistent Storage for uploads
Step 1: Create MySQL Secret
Create secret file:
apiVersion: v1
kind: Secret
metadata:
name: mysql-pass
type: Opaque
data:
password: bXlwYXNzd29yZA==
Apply:
kubectl apply -f mysql-secret.yaml
Step 2: Create Persistent Volume for MySQL
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mysql-pv-claim
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
Apply:
kubectl apply -f mysql-pvc.yaml
Step 3: Deploy MySQL
apiVersion: apps/v1
kind: Deployment
metadata:
name: wordpress-mysql
spec:
selector:
matchLabels:
app: wordpress
tier: mysql
template:
metadata:
labels:
app: wordpress
tier: mysql
spec:
containers:
- image: mysql:5.7
name: mysql
Apply:
kubectl apply -f mysql-deployment.yaml
Step 4: Create MySQL Service
apiVersion: v1
kind: Service
metadata:
name: wordpress-mysql
spec:
ports:
- port: 3306
Apply:
kubectl apply -f mysql-service.yaml
Step 5: Create WordPress Persistent Volume
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: wp-pv-claim
spec:
accessModes:
- ReadWriteOnce
Step 6: Deploy WordPress
apiVersion: apps/v1
kind: Deployment
metadata:
name: wordpress
spec:
replicas: 2
Apply:
kubectl apply -f wordpress-deployment.yaml
Step 7: Expose WordPress Service
apiVersion: v1
kind: Service
metadata:
name: wordpress-service
spec:
type: LoadBalancer
Apply:
kubectl apply -f wordpress-service.yaml
Step 8: Access Your WordPress Site
Run:
kubectl get svc
Find EXTERNAL-IP and open it in browser.
Step 9: Configure Domain Name
Point your domain A record to:
- Kubernetes Load Balancer IP
Step 10: Add SSL Certificate
Install Cert Manager or Ingress with Let's Encrypt.
Common Problems and Fixes
Pod CrashLoopBackOff
Check logs:
kubectl logs pod-name
Database Connection Error
Verify:
- MySQL service name
- Password secret
Storage Not Mounting
Check PVC:
kubectl get pvc
Best Practices
Use Managed DB
Consider RDS/Cloud SQL instead of container MySQL.
Use CDN
Improve WordPress performance.
Enable Backups
Snapshot volumes regularly.
Real-World Considerations
Kubernetes is powerful but may be overkill for:
- Small blogs
- Personal websites
Ideal for:
- Agencies
- SaaS companies
- High-traffic sites
FAQs
Is Kubernetes good for WordPress?
Yes, for scaling and high availability.
Is Kubernetes overkill for one site?
Usually yes.
Final Thoughts
Deploying WordPress on Kubernetes gives you scalability, reliability, and automation, but it adds complexity. For enterprise or high-traffic environments, Kubernetes is an excellent platform.
