Recently, we need WordPress for some work hosted on Google Kubernetes Engine. So yeah it’s definite we would install WordPress on GKE with Helm but my Senior DevOps Engineer decided to use Google Cloud SQL for this instead MariaDB.
So here is another blog on Cloud from my side after learning and doing...
Before starting this, I’m assuming that you have a little bit hands-on knowledge of Kubernetes (k8s), WordPress and understanding of basic terms of Kubernetes and SQL.
Note: This tutorial includes installation of WordPress via Helm, make sure you are following the same sequence of creation and installation of service/tools because once the user id/password of WP admin get store in SQL, it is not possible to change it via helm upgrade through values.yaml file(it could be a bug in wordpress helm). We were facing same, then after we have to delete SQL instance, delete DB and install everything again, put values in file to login in WP Admin.
Google Kubernetes Engine (GKE)
Google Kubernetes Engine (GKE) is a managed, production-ready environment for deploying containerized applications. It’s a perfect combination or I should say a blend of Iaas and PaaS making it as Kubernetes as a Service or Container as a Service which Google was using since 2003 as its internal orchestrator till 2015 when it gets open-source with a benefit of autoscaling of the cluster, integration of Stackdriver, fluentd, Prometheus, VPN etc. Kubernetes Engine enables rapid application development and iteration by making it easy to deploy, update, and manage our applications and services with no vendor lock-in which means you’re free to take your applications out of Kubernetes Engine and run them anywhere Kubernetes is supported, including on your own on-premises servers.
Let’s start from creating a Kubernetes Cluster:
gcloud container clusters create wordpress-cluster \
--num-nodes 2 \
—-zone us-central1-a \
—-machine-type n1-standard-2 \
It will take some time to create K8S cluster:
Run below command to view cluster or you can view it in UI too
gcloud container clusters list
We need to create namespace first; namespaces are virtual clusters which scopes of resources among users, environments and projects. Read about it from official docs.
We will install every resource in the cluster within wordpress namespace.
kubectl create namespace wordpresskubectl get ns (to see all namespaces in your cluster)
Create Cloud SQL Instance and Database
Cloud SQL is a fully managed or no apps database service that makes it easy to set up, maintain, manage, and administer your relational databases on GCP. Cloud SQL has a high capacity capable of handling terabytes of storage. The databases are relational, which means that you are simply going to be running queries such as SELECT statements to read fields data or INSERT statements to write fields data.
Cloud SQL supports many clients such as CloudTrail, App Engine, and G Suite Scripts. It also supports other applications and tools that you might be used to, like SQL Workbench, Toad, and other external applications using standard MySQL drivers.
Let's create Cloud SQL Instance in GCP Console:
Choose MySQL, ensure 5.7 version is selected
Enter Instance ID whatever you want
Set Root password whatever you want
In Show configuration options: Select Machine type and storage; select machine type, storage type and enter storage capacity according to your need
That’s it, now hit Create.
When all done, your instance will get a public IP.
Upon clicking on the Instance ID, you’ll get SQL instance overviews like CPU Utilization, Public IP, Configurations and all.
In the left navigation area, go to Connections option and in the Connectivity section, add an authorized network with
Below connections, goto Users and Create a user account with name and password.
Below Users, goto Database and create DB, just by entering the name.
Now we are done with Google Cloud SQL setup. It’s time to install Helm for installation of WordPress.
Helm is just package manager for Kubernetes for deploying and managing complex applications easily and flexibly. It’s what NPM is for Node, Hombrew for Mac etc.
For a better explanation, you can visit my last blog there I’ve explained about Helm in a detailed way or you can also visit Helm Official Docs.
Jenkins on Google Kubernetes Engine(GKE) with Helm
Helm is a Package Manager for Kubernetes and by deploying any service via Helm on GKE reduce a lot of step of…
To install and setup Helm( v2.14.1) in your cluster:
wget https://storage.googleapis.com/kubernetes-helm/helm-v2.14.1-linux-amd64.tar.gztar zxfv helm-v2.14.1-linux-amd64.tar.gz cp linux-amd64/helm .kubectl create clusterrolebinding cluster-admin-role --clusterrole=cluster-admin --user=$(gcloud config get-value account)kubectl create serviceaccount tiller-server --namespace kube-systemkubectl create clusterrolebinding tiller-admin-role --clusterrole=cluster-admin --serviceaccount=kube-system:tiller-serverhelm init --service-account=tiller-serverhelm repo updatehelm version
Again if you want a better explanation of each command above, go to my previous blog from the above link.
Yay! we are done with Helm installation, now let’s move forward to install WordPress.
WordPress is open source software you can use to create a beautiful website, blog, or app-based on PHP and MYSQL. WordPress was released on May 27, 2003, by its founders, Matt Mullenweg and Mike Little, as a fork of b2/cafelog. The software is released under the GPLv2 (or later) license. WordPress is used by more than 60 million websites, including 33.6% of the top 10 million websites as of April 2019, it is one of the most popular content management system (CMS) solutions in use. It has also been used for other application domains such as pervasive display systems (PDS).
Since we are using our own MySQL we need to clone the GitHub repo of Helm, make some changes in the configuration file like DB username, password, IP of MySQL etc and then deploy it via Helm command.
Clone the Helm Charts repo, either in cloud-shell or your local-system
mkdir helm-wpcd helm-wp/git clone https://github.com/helm/charts.gitcd charts/stable/wordpress/
Once in there you’ll find there a
values.yaml which is a configuration file of WordPress.
Now you need to make some essential changes in this file which are as follows (you can use your own value, I’m using just mine)
- wordpressUsername: admin [line 41]
- wordpressPassword: my-password [line 47]
- wordpressEmail: firstname.lastname@example.org [line 52]
- host: [IP_Address of Cloud SQL Instance] [line 151]
- user: wp-user [line 154] (values you enter while setting up cloud SQL)
- password: “my-password” [line 157]
- database: wp_db [line 160]
- port: 3306 [line 163]
- In the MariaDB section,enabled: false [line 172]
- In the service section, type: ClusterIP [line 214]
- port: 6002 [line 217]
- In the ingress section, enabled: false [line 283]
That’s it, now we are ready to launch WordPress.
Run the following commands:
cd /helm-wp/charts/stable/helm install --dry-run --debug --namespace wordpress --name wordpress --values ./wordpress/values.yaml ./wordpresshelm install --namespace wordpress --name wordpress --values ./wordpress/values.yaml ./wordpress
After successful installation, run
kubectl -n wordpress get podskubectl -n wordpress get svckubectl -n wordpress get ing
See there is no ingress till now because we disabled ingress in
values.yaml now will create our own ingress.
To get ingress, we need to install nginx-ingress-controller, we will do it via Helm.
helm install --namespace wordpress --name wp-nginx-ingress stable/nginx-ingress
Now make an ingress file and paste the following code.
kubectl -n wordpress apply -f ingress.yaml to deploy ingress.
Now we are done with all major task.
Now a small task has left; mapping of a subdomain with load balancer IP. For this, I’m assuming you already have a domain, we just need to create
A Record in DNS of our domain manager with value our ingress IP and host what we mentioned in our
This mapping would some time to get attach with load balancer IP.
Once done, open your host or subdomain, in my case it’s
You will get a landing page.
For login just enter
dev.rohankalhans.xyz/wp-admin a login page will appear. Enter the username and password that you have given in
values.yaml of WordPress.
After successful login, you get your beautiful WordPress dashboard.
Ensuring data is stored in MySQL database
Open your Google Cloud Shell and enter these commands:
gcloud sql connect cloud-sql-for-wordpress --user=rootshow databases;use [DB_name_that_you_created];show tables; (there will be a tables with users name)select * from [table_name];
So yeah, that’s how you set up WordPress on Kubernetes via Helm using Google Cloud SQL.
And all done.
To join our community Slack team chat 🗣️ read our weekly Faun topics 🗞️, and connect with the community 📣 click here⬇