- Google Kubernetes Engine cluster. Follow the Google Kubernetes Engine Creating a Cluster guide. When creating a cluster, make sure you select a Kubernetes version 1.9 or greater.
- Google Cloud SQL instance. Follow the Google Cloud SQL Creating instances guide.
- Google Cloud SQL credentials saved locally as
credentials.json
. You'll need them later. See Connecting Cloud SQL to Kubernetes Engine. - A domain and access to its DNS settings. These instructions use the generic domain name
mysite.com
as an example site domain. You should replace it with your own domain name.
- Install GKE WordPress project locally
$ mkdir -p gke-wp{wp-sites} && cd gke-wp
$ git clone https://github.com/stcox/gke-wordpress.git && cd gke-wordpress
- Install Helm & Tiller
$ curl https://raw.githubusercontent.com/kubernetes/helm/master/scripts/get | bash
$ kubectl create -f tiller-rbac-config.yaml
$ helm init --service-account tiller
- Install core cluster services: Nginx-Ingress, Kube-Lego, Redis, and Dynamically Provisioned Storage Classes.
$ helm install nginx-ingress
$ helm install kube-lego --set [email protected]
$ helm install redis
$ kubectl create -f ./gke-wordpress/storageclass.yaml && cd ..
The example site uses mysite-com
, for the site's namespace, and mysite.com
for the domain. All WordPress site namespaces are automatically prefixed with wp-
to make them easier to find; consequently, the example namespace will appear as wp-mysite-com
in k8s.
The example domain name is, mysite.com
must be substituted with your own domain.
Kube-lego provides free LetsEncrypt SSL certificates for any domains you control. LetsEncrypt is enabled by default, but can be disabled in the sites values.yaml
file.
-
Create an A record for your domain,
mysite.com
at domain registrar (Godaddy, et al.), and point it to your Ingress IP address. Get your cluster's Ingress IP Address. -
Configure site in
values.yaml
.
$ cp ./gke-wordpress/wordpress/values.yaml ./wp-sites/mysite-com.yaml
$ nano ./wp-sites/mysite-com.yaml
- Create Persistent Disk with disk size and cluster zone.
$ gcloud compute disks create --size=10GB --zone=us-central1-a mysite-com
- Deploy site to cluster.
$ helm install -f ./wp-sites/mysite-com.yaml ./gke-wordpress/wordpress
- Upon deploying a site:
- Add the following lines to wp-config.php:
- define('WP_CACHE_KEY_SALT', 'mysite-com');
- define('WP_REDIS_CLIENT', 'pecl');
- define('WP_REDIS_SCHEME', 'tcp');
- define('WP_REDIS_HOST', 'redis.redis');
- define('WP_REDIS_PORT', '6379');
- Install Redis Object Cache plugin, and select the Connect button to connect to Redis, and
- Install NGINX Cache plugin and set Cache Zone Path to
/var/run/nginx-cache
, and set Purge Cache, to ensure changes appear on your website promptly.
- Add the following lines to wp-config.php:
This project was inspired by daxio/k8s-lemp and builds on it with the various other official Docker images and Kubernetes applications mentioned previously.