- Git
- 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 to your locally as
credentials.json. You'll need them later. See Connecting Cloud SQL to Kubernetes Engine. - [Optional] A domain and access to its DNS settings. These instructions use the generic domain name
mysite.comas an example site domain. You should replace it with your own domain name.
- Using wordpress google cloud marketplace, configure & deploy. https://console.cloud.google.com/marketplace/details/google/wordpress
- Connect to your GKE (Google Kubernetes Engine)
$ gcloud container clusters get-credentials {YOURGKECLUSTERNAME} --zone {YOURGKECLUSTERZONE} --project {YOURPROJECTNAME}- Expose your wordpress service from your google cloud shell
$ export APP_INSTANCE_NAME={YOURWORDPRESSSERVICENAME} # From Step 1
$ export NAMESPACE={YOURWORDPRESSNAMESPACE} # From Step 1
$ kubectl patch svc "$APP_INSTANCE_NAME-wordpress-svc" \
--namespace "$NAMESPACE" \
--patch '{"spec": {"type": "LoadBalancer"}}'- Get your wordpress site address
$ SERVICE_IP=$(kubectl get svc $APP_INSTANCE_NAME \
--namespace $NAMESPACE \
--output jsonpath='{.status.loadBalancer.ingress[0].ip}')
$ echo "http://${SERVICE_IP}"- Scale up or down your wordpress application
$ kubectl scale deployment/{YOURWORDPRESSPOD_NAME} --replicas=N #Example 3 for scaling up to 3 pods, 1 for scaling down to 1 pods*If you want to simplify above script, just create bash script ie: publish.sh and copy all command from step 2-4 into it.
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.comat domain registrar (Godaddy, et al.), and point it to your Ingress IP address. Get your cluster's Ingress IP Address. Or just edit in your /etc/host for testing purpose. -
Install GKE WordPress project locally
$ git clone https://github.com/ekarisky/gke-wordpress.git && cd gke-wordpress- Configure site in
values.yaml.
$ mkdir wp-sites
$ cp gke-wordpress/wordpress/values.yaml wp-sites/mysite-com.yaml
$ nano wp-sites/mysite-com.yaml- 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 legoEmail=MYEMAIL@MYSITE.COM
$ helm install redis
$ kubectl create -f storageclass.yaml- Deploy site to cluster.
$ helm install -f wp-sites/mysite-com.yaml wordpress- Scale up or down your wordpress application
$ kubectl scale deployment/{YOURWORDPRESSPOD_NAME} --replicas=N #Example 3 for scaling up to 3 pods, 1 for scaling down to 1 pods*If you want to simplify above script, just create bash script ie: publish.sh and copy all command from step 2-6 into it.
- Upon deploying a site, edit the site and:
- 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.
This project was forked from stcox/gke-wordpress, and modified accordingly This project was inspired by daxio/k8s-lemp and builds on it with the various other official Docker images and Kubernetes applications mentioned previously.