WordPress implementation on Kubernetes. Based on the tutorial from Kubernetes' documentation, but on real cluster (no Minikube).
Simplest as possible, to be useful as Kubernetes cluster deployment exercise/test.
WordPress + MySQL configurations require the creation of a cluster with PersistentVolumes
and Secrets
. I'm also using Kustomize for the Secret
generator.
Following the tutorial, the first step is adding a Secrets
generator using a kustomization file.
I generated a random password for MySQL: GA3DIMJRGUZTSNZT
. For learning purposes, such values are exposed, but this should never be a practice (neither in practice environments).
The following code must be added to kustomization.yaml
:
#kustomization.yaml
secretGenerator:
- name: mysql-pass
literals:
- password=GA3DIMJRGUZTSNZT #arbitrarily random password
This MySQL container image is specifically configured for WordPress usage, which makes connections easier. It also mounts the PersistentVolume
at /var/lib/mysql
. The MYSQL_ROOT_PASSWORD
environment variable sets the database password from the Secret
.
It also contains a Service
and a Deployment
, where further data is declared.
The WordPress container mounts the PersistentVolume
at /var/www/html
for website data files. The WORDPRESS_DB_HOST
environment variable sets the name of the MySQL Service
defined above, and WordPress will access the database by Service
. The WORDPRESS_DB_PASSWORD
environment variable sets the database password from the Secret
kustomize generated.
After defining both mysql.yaml
and wordpress.yaml
files, those should be referenced on kustomization.yaml
:
#kustomization.yaml
resources:
- mysql.yaml
- wordpress.yaml