Deadsimple Wordpress in Kubernetes

2 minute read Updated

A microtutorial to run WordPress locally in Kubernetes under Docker.

How to install Wordpress with Bravada theme for local development in 8 steps.

Tip: If this tutorial is too high-level for you, have a look here instead.

Step 1: Install Dependencies

Step 2: Clone Sources

  1. Clone WordPress Helm Chart from OSA
  2. Clone WordPress from Pantheon Systems

Put them next to each other.

Step 3: Create Cluster

Bootstrap K3s in a multi-node Docker cluster:

k3d cluster create k3s-wordpress -i rancher/k3s:latest \
    --api-port 6550 --agents 2

Step 4: Update WordPress

Remove spurious themes and push to remote:

cd wordpress && \
rm -rf wp-content/themes/twenty* && \
git commit -m "perf: ⚡️ remove theme cruft" && \
git push -u gitlab default

Helm Chart requires GitLab for WordPress customizations.

Step 5: Prepare Chart

cd ../wordpress-helm && \
cp install.sh.example install.sh && chmod +x install.sh && \
cp values-local.yaml.example values-local.yaml

Edit values-local.yaml and your own CLI image if desired:

values-local.yaml
227initImage:
228  repository: comfusion/wp-cli-docker
229  tag: 0.1.6.1
230  pullPolicy: Always

Find and edit themes_install section to add Bravada and TwentyTwentyOne themes:

values-local.yaml
45  themes_install:
46  - twentytwentyone
47  - bravada
48  theme_active: bravada
49  theme_fallback: twentytwentyone

Also configure git_repo to use GitLab repo created in Step 4.

Step 6: Deploy Chart

export KUBECONFIG=$(k3d kubeconfig write k3s-wordpress)

kubectl create namespace sandbox && \
./install.sh -n sandbox

Wait until pods are Ready up with watch kubectl get pods -n sandbox. Debug init-container with Lens…

Step 7: Connect to Lens

Write kubeconfig:

k3d kubeconfig write k3s-wordpress -o `pwd`/kubeconfig-k3d-dev

Open kubeconfig-k3d-dev in Lens:

lens

Watch wordpress-production-0 Ansible logs for errors:

lens

Step 8: Browse the Site

With pods Ready proxy the ClusterIP service (prefix with sudo -E if needed):

kubectl port-forward service/wordpress-production 80:8080 -n sandbox

Browse the site:

Enable Redis in values-local.yaml. Run ./install.sh -n sandbox. Profit.