WordPress Kubernetes Deployment: Step-by-Step Guide

Published 15/09/25 · Read 3 minute

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.


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:

minikube start
kubectl create namespace wordpress

Step 2: Deploy MySQL (or MariaDB)

Create a mysql-deployment.yaml:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: mysql
  namespace: wordpress
spec:
  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
            - name: MYSQL_DATABASE
              value: wordpress
            - name: MYSQL_USER
              value: wpuser
            - name: MYSQL_PASSWORD
              value: wppass
          ports:
            - containerPort: 3306

Then expose it with a service:

kubectl apply -f mysql-deployment.yaml
kubectl expose deployment mysql --type=ClusterIP --port=3306 -n wordpress

Step 3: Deploy WordPress

Create a wordpress-deployment.yaml:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: wordpress
  namespace: wordpress
spec:
  replicas: 2
  selector:
    matchLabels:
      app: wordpress
  template:
    metadata:
      labels:
        app: wordpress
    spec:
      containers:
        - name: wordpress
          image: wordpress:6.6-php8.1-apache
          env:
            - name: WORDPRESS_DB_HOST
              value: mysql.wordpress.svc.cluster.local:3306
            - name: WORDPRESS_DB_USER
              value: wpuser
            - name: WORDPRESS_DB_PASSWORD
              value: wppass
            - name: WORDPRESS_DB_NAME
              value: wordpress
          ports:
            - containerPort: 80

Expose WordPress service:

kubectl apply -f wordpress-deployment.yaml
kubectl expose deployment wordpress --type=NodePort --port=80 -n wordpress

Check services:

kubectl get svc -n wordpress

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

READ :  Serverless WordPress Hosting on AWS: Beginner’s Tutorial

Example pvc.yaml:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: wp-pvc
  namespace: wordpress
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi

Step 5: Ingress + Domain Setup

  1. Install NGINX Ingress Controller:

minikube addons enable ingress
  1. Create an Ingress resource to map domain to WordPress service.

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: wordpress-ingress
  namespace: wordpress
spec:
  rules:
    - host: mywordpress.local
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: wordpress
                port:
                  number: 80
  1. Update your /etc/hosts to point mywordpress.local to Minikube IP.


Step 6: Scaling WordPress Pods

To scale WordPress containers:

kubectl scale deployment wordpress --replicas=5 -n wordpress

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.

READ :  Cara Setting Yoast SEO di WordPress (Pemula)

5. How do I handle backups?
Use Velero for cluster backups and regular database dumps.