Deploying WordPress by Integrating Google Cloud Platform with Kubernetes
TASK OVERVIEW
- Create multiple projects namely developer and production
- Create VPC network for both the projects
- Create a link between both the VPC networks using VPC Peering.
- Create a Kubernetes Cluster in developer project and launch any web application with the load balancer.
- Create a SQL server in the production project and create a database.
- Connect the SQL database to the web application launched in the Kubernetes cluster.
introduction:
Google Cloud Platform: Just like other clouds (AWS, Azure, etc ) Google has its own cloud. Google Cloud Platform (GCP) is a collection of Google’s computing resources, made available via services to the general public as a public cloud offering.
Google Kubernetes Engine: GKE
Google Kubernetes Engine (GKE) provides a managed environment for deploying, managing, and scaling your containerized applications using Google infrastructure. The GKE environment consists of multiple machines (specifically, Compute Engine instances) grouped together to form a cluster.
Practical Part:
We have to create two different projects such as Dev and Prod.
note: since I am using google temporary lab I am going to create two VPN in different location as shone bellow
note: Before we create VPC’s, we need to ensure that compute engine and Kubernetes engines API’s are enabled in projects or not, if not we need to enable them as below:
fill the basic details of the vpc and click on create and weight for some time
after creating the 1 st vpc I'm going to create another vpc in different location
as shone bellow
Click on create
finally we are successful in creating the 2 vpc in google cloud
but the challenge is they are not communicating with each other to overcome this we will use another service in google cloud called VPC network peering
create a VPC network peering in developement team as shone dellow
gave a name to your peering and give details about you present vpc and peered vpc network name as he above so that google will try to connect both the vpc
but you will see like this
because you have to give permission from another side also to do that create a vpc network peering in other vpc as well
click on create it will take some time
after that automatically preening will start
by doing this both the vpc can communicate each other by using google isolate cables so that our data is very secure
In the Prod project: We have to launch Kubernetes Cluster for WordPress pods using GCP Google Kubernetes Engine Service. (With scale-out and Load balancer functionality)
Go to Kubernetes engine of prod project and click create cluster as below:
Fill the basic cluster info, note that you have to select the same region which you used for creating vpc and select all the zones available in that region.
give a name to your cluster and go to default-pool
and change the number of nodes to 1 instead of three because currently I am using the trial version of GCP account. Hence, I don’t have enough resources to maintain more number of nodes.
Go to nodes section and change the model of nodes to N1 because this consumes very less number of resources than the other node types.
Go to the networking and choose the vpc and subnet which you created recently.
Then click create cluster and wait for some time.
now We have to launch Kubernetes Cluster for WordPress pods using GCP Google Kubernetes Engine Service.
We achieve this task by using gcloud shell, Now go to cluster and click ‘Connect’, then copy the shell command into your clipboard.
Now, activate cloud shell and paste the command which you had copied in your previous step to connect to the cluster.
Execute the commands for checking a number of nodes and pods in your cluster.
We can see three nodes created at three different zones of asia-southeast2 region. Currently, as we did not create pods, hence the command is none.
Now we create a pod in this cluster with the help of command
create deployment mywp — — image=wordpress
We use ‘deployment’ keyword in the command so as to tell Kubernetes controller to monitor this particular pod and report to docker engine if there is any abnormality in this pod.
Check the status of pods by running ‘kubectl get pods’ or ‘kubectl get all -o wide’
Now we create a load balancer service for these pods by using the following command:
kubectl expose deployment wordpress-system — type=LoadBalncer — port=80.
Here keyword expose in this command means we are asking cluster to expose this pod to public internet by assigning it with an internet ip.
After creating, you have to use external ip to login into WordPress pod as shown in below figure:
Click continue, don’t click on let’s go, now we need to connect MySQL DB to this WordPress server.
In the Dev project We have to create MySQL Database using GCP SQL service.
Now we create MySQL db as follows:
Fill the parameters and enter the password for root user , remember the password we shall use it in later part
After successfully creating MySQL db, we should do the groundwork for establishing a connection between WordPress and MySQL db
Here I am trying to create a rule that says DB can be accessed by public network all users, that is 0.0.0.0/0
With this, we have successfully integrated our DB with WordPress.
We can scale out pods by using command in gcloud shell as:kubectl scale deployment wordpress-groups — replicas=5
Connect me on my LinkedIn as well.