Skip to content

Google Kubernetes Engine WordPress with Google Cloud SQL in Helm Charts

License

Notifications You must be signed in to change notification settings

ekarisky/gke-wordpress

 
 

Repository files navigation

Wordpress on Google Kubernetes Engine

Pre-requisites

  • 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.com as an example site domain. You should replace it with your own domain name.

Deploy Wordpress Easy Way

  1. Using wordpress google cloud marketplace, configure & deploy. https://console.cloud.google.com/marketplace/details/google/wordpress
  2. Connect to your GKE (Google Kubernetes Engine)
$ gcloud container clusters get-credentials {YOURGKECLUSTERNAME} --zone {YOURGKECLUSTERZONE} --project {YOURPROJECTNAME}
  1. 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"}}'
  1. 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}"
  1. 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

Notes

*If you want to simplify above script, just create bash script ie: publish.sh and copy all command from step 2-4 into it.

Deploy Wordpress Hard Way using Helm

Installation

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.

  1. 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. Or just edit in your /etc/host for testing purpose.

  2. Install GKE WordPress project locally

$ git clone https://github.com/ekarisky/gke-wordpress.git && cd gke-wordpress
  1. 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
  1. 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
  1. 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 storageclass.yaml
  1. Deploy site to cluster.
$ helm install -f wp-sites/mysite-com.yaml wordpress
  1. 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

Notes

*If you want to simplify above script, just create bash script ie: publish.sh and copy all command from step 2-6 into it.

Post-requisites

  • 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.

Acknowledgements

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.

About

Google Kubernetes Engine WordPress with Google Cloud SQL in Helm Charts

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • HTML 100.0%