Set up Multi-Nodes Kubernetes Cluster along with WordPress & MySQL on GCP Cloud
Project Requirements are as follows:
- Create 2 different projects one for dev & other for Prod environment
- Create 2 VPC’s in 2 different regions, one in Singapore region & other one in US region.
- Establish VPC peering between the 2 VPC’s created above
- Create multi-node Kubernetes cluster in Singapore VPC.
- Launch WordPress instance using docker image in above cluster’
- Create a LoadBalancer & expose it to port 80 so as to access WordPress.
- Launch MySQL DB instance in Prod VPC (US region)
- Ensure that the LoadBalancer able to access WordPress.
- WordPress in turn able to connect to MySQL instance created above.
- Create IAM users & assign roles & test the privileges.
Let’s start creating separate projects i.e. one for Dev & other for Prod as follows
Create another project for Prod.
Also, we’ll need to enable Compute Engine API for myproproject
Now let us try to create VPC in each of the above project
We’ll create VPC in Singapore region for mydevproject & another VPC within US region for myproproject.
Now we need to create a firewall rule for above VPC
Similarly we’ll create a VPC in US region & set up firewall rule for it.
Now , let’s set up firewall rule for above VPC
VPC Peering as a concept using with O.S. in different VPC can communicate with each other using pvt IP’s through GCP owned high speed otpical fiber network. It reduces cost, latency & improves performance to a great extent.
Now let us try to launch instances in each of the above VPCs
Launching instance in Singapore region.
we’ll select CentOS 7 image
select VPC from within the networking section as below & hit create to launch instance.
Now , lets launch one instance in myprodproject
select VPC from within the networking section as below & hit create to launch instance.
finally instance launched.
We can verify the same using gclod command.
now let’s try to ping from devinstance to prodinstance using ping command
We can see that ping doesn’t happen from devinstance to prodinstance.
This can be resolved using VPC peering
For VPC peering we need to create peering connection as under
We should note the project id & vpc network name before creating VPC peering connection.
The status still shows inactive as we need to allow peering from other side as well i.e. from vpcprod-us to vpcdev-sg as well
After doing this VPC peering is active at both the sides.
and we can see that the devinstance is able to ping prodinstance now
Thus, VPC peering helps to communicate instances in different VPC’s using private IP’s instead of public IP’s. Thus it’s more secure, high speed & reduces latency.
Now we need to set up Kubernetes cluster in mydevproject
Before this we need to enable Kubernetes KPI engine
Once Kubernetes API Engine is enabled we can create cluster as “create cluster” button will be enabled as shown below
We can select appropriate region & node locations as below
select N1 machine type from within General Purpose Machine Family
We can connect to above kubernetes cluster as below
next step is to launch a pod & deploy WordPress in it.
the command used for deploying Wordpress is:
kubectl.exe create deployment mywp — image=wordpress
Launch a POD with WordPress image
We can verify in which node the POD is running as under
identify the node in which POD is running
Kubectl deployment monitors each POD & in case if it goes down it will launch another POD with similar configuration immediately. Thus it manages POD lifecyle as well as rolling updates.
We now need to expose above
Once WordPress is setup we need to create a LoadBalancer service & expose it
Next step is to set up MySQL instance in myprodproject as shown in following steps.
select MySQL database engine
Specify DB instance name, password & region details.
We need to edit the networking settings for above MySQL db instance.
We can connect to this instance using Active Cloud Shell as under
Now let’s create our own database
Now, last step is to connect WordPress instance to this MySQL database instance. As per the project requirement WordPress will serve as a front end & MySQL will be used to store WordPress data which we store in the website.
Using public IP (34.87.175.117) of WordPress instance we can launch it as below:
Next step is to configure MySQL database (created above in myprodproject) with WordPress
We can specify MySQL DB instance details (IP of DB instance we can get from the following screen in GCP)
Finally we are ready with WordPress installation.
Kudos!! We have set up installed WordPress instance successfully and now we can create our pages..
We are now ready to create our own blogs..
We can confirm that the blog is published..
Same data we can verify in MySQL DB as below
Below Table indicates that the website data has been stored in WordPress table in the configured database.
Now we’ll try to create IAM users & see how to play around with roles.
We’ll need gmail id of the user so as to set up roles.
Once we have created the account as above the user will receive mail from the sender.
User is unable to create MySQL DB as he has only viewer role
Finally, we can destroy both the projects, VM instances, SQL DB instance, VPC networks.
Thus using Google Kubernetes Engine , we deployed multi-node cluster & successfully launched WordPress application inside a container using docker image.
Also, set up MySQL DB as a back-end to store WordPress blog data.
Thank You!