How to run WordPress on Kubernetes
This guide covers creating K8s volumes and configuring a WP instance with a MySQL database in a most simple way — a perfect introduction to Kubernetes for newbies.
It is a direct followup to the articles on dockerizing and automating the delivery of WordPress projects, allowing you to introduce the power of Docker to your dev setup. Now it’s time to unleash it on a cluster of Google-powered nodes.
Configure a PersistentVolume in the K8s cluter
Since we only have one node in the cluster we’ll use a hostPath
volume. This type of volume mounts the path from the node's filesystem into K8s.
Create volumes.yml
apiVersion: v1
kind: PersistentVolume
metadata:
name: local-pv-1
labels:
type: local
spec:
capacity:
storage: 10Gi
accessModes:
- ReadWriteOnce
hostPath:
path: /k8/volume/pv-1
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: local-pv-2
labels:
type: local
spec:
capacity:
storage: 10Gi
accessModes:
- ReadWriteOnce
hostPath:
path: /k8/volume/pv-2
This config will create two R/W 10GB volumes in the node paths:
/k8/volume/pv-1
/k8/volume/pv-2
Create your K8s volumes
To create the volumes, run
kubectl apply -f volumes.yml
You can run the command below to check if eveything’s correct:
kubectl get pv
NAME CAPACITY ACCESSMODES RECLAIMPOLICY STATUS CLAIM STORAGECLASS REASON AGE
local-pv-1 10Gi RWO Retain Available 13s
local-pv-2 10Gi RWO Retain Available 13s
Like what your read? Check out the full guide here!
Other posts: