How to Deploy a Wordpress site on a Kubernetes Clusters with Load Balancer Implementation upon Google Cloud Platform(GCP)

 Hello Connections, here i  have posted an article on how to use Google Cloud Platform , to deploy our Webserver inside Kuberenetes Clusters, where these clusters are connected with  load balancer ,and at last we connected our database with this Webserver . This article include all the process & prerequisite to perform this task.



Task Description :

1. Create multiple projects namely developer and production.

2. Create VPC network for both the projects.

3. Create a link between both the VPC networks using VPC Peering.

4. Create a Kubernetes Cluster in developer project and launch any web application with the Load balancer.

5. Create a SQL server in the production project and create a database.

6. Connect the SQL database to the web application launched in the Kubernetes cluster.

Now we will start the task & i will discuss all the step by step process or method to perform this task.

Step 1: Create two projects one for developer & another                                             for production.

Create one project for the developer from where developer can work in their our own projects.

Create one project for the production department from where production guys can work in their our own projects.

Step 2: Create a VPC network for both the projects.

Vpc network is available in GCP inside Networking Section

After clicking on the create VPC network, we will create the network according to our requirements.First we will create for Dev Project and after that prod project.





After Clicking on Create our Vpc network,it will be created.


As you can see that we have created a VPC network for the Dev project, We can see its details by clicking on the vpc network name.


Now, we will follow the same step for creating VPC Network for Prod Project.



After Clicking on Create our Vpc network,it will be created.



As you can see that we have created a VPC network for the Prod project, We can see its details by clicking on the vpc network name.


Step 3:Create the VPC peering for both the network.



Here you can see that there is not a single vpc peering has been created yet , so we are going to create the vpc peering for the prod project by clicking on Create Connection . This VPC Peering will connect our both VPC network together with GCP private network.



Here we provide both our VPC network names and by clicking on the create our peering connection for Dev will be created.


Now you can see that vpc peering for the Dev project has been created but it is in inactive mode as the peering connection will be established only when both of the vpc network connected with each other, so similar kind of peering we have to create for Prod project also.




Here we can see that vpc-peering for the both the projects has been created & also the status is active for the both the vpc peering.
Now our both the projects, which are in different zones, have connection with each other using GCP private network.
Whenever we use any technology or a tool , we can use it in two ways either from GUI or from CLI . So we know that we are human beings and we are always comfortable with the GUI , but it is always a good practice to know about the commands that are working in background, so similarly for google cloud platform we have CLI availbale ,if we want to use the same then we have to install the SDK for the gcloud. So first we have to download the software & then we can proceed with the CLI.

We can download the software from the given link: https://cloud.google.com/sdk/docs/quickstart-windows

Once you click on the google cloud SDK installer the software will downloaded and just we have to install it & use it. 


                                       
As soon as we open it, it will require our credentials to login with our gcloud account.




Once you are logged in your CLI interface will connect you with your GCP. You can see/lis your projects using command : gcloud projects list

Step 4: Create the kubernertes cluster & launch the                                                     Kubernetes pods.

Now we are going to create the clusters in the Dev project so that we can deploy our web server inside the pods, we are doing this for high availability.
We will find this service in Kuberenetes Engine inside GCP.







Now since we have configured our Kuberenetes, we are going to use it and deploy web server inside it.
To connect with our Kubernetes Cluster it provides us the command that we have to enter either in cloud shell or GCP CLI.

Now we can do the further things that is related to the kubernetes like launching a pods , deployment , exposing the server etc. So before that we need one more command to use the kubernetes from the command line i.e; kubectl so we have to install these command in your system Command : gcloud components install kubectl.


So now i am going to create a deployment to launch a wordpress server inside the nodes of cluster that we created upon GCP, so to create a deployment we need the image name of the wordpress. 

So to create the deployment we have to use a command :

kubectl create deployment word-press --image=wordpress

As you can see that we have created a deployment successfully & we can also check that our pods & deployments are successfully launched or not with the help of command i.e:

kubectl get deployments/deploy ( to know about the deployment )kubectl get pods ( to know about the pods )

we can also check the status or details of nodes that we have launched inside our kubernetes cluster , with the help of command 

kubectl get nodes -o wide 




Now we will create replica or copy of our pods for the high availability so that, if one pod is down other is working fine in place of that, moreover it will help us in handling different request so the load will be distributed among all the three pods using load balancer.

So as tothe no pods the help of pods with the help of replicas & with command i.e;
kubectl scale deployment word-press --replicas=3

                                       

So here we can see that number pods has been increased and all the pods are running , for more information about the pods we can use command:

kubectl get pods -o wide


We can see the service running currently inside kubernetes cluster with the command:

kubectl get svc/services




Now we will be integrating the load balancer with our kuberentes clusters, this load balancer ensures us that the load is distributed among all the pods using Round Robin technique.
kubectl expose deployment word-press --type=LoadBalancer --port=80


after that we can check the service again it will show the another service has been started but for few seconds it will show External Ip pending but after sometime it will provide an ip.

Here you can see that the load balancer has also created on the top of the google cloud , so now you can use this load balancer to expose our IP, so that anyone from public world can use our web server or our website.


Step 5: Create a SQL server in the production project                                                 and create a database.

Now we have to create the a database server so that we can integrate it with the our wordpress server.

So here we will create a database instance on gcp cloud , so we use the production project to create the database server. So when we launched or create the database then in a parallel way it will create a MySQL instances.




As you can see that there is no SQL instances present so when we click on the create instance option it will create a SQL instances for us.



Here you can see that there is three types of database instances are available , so it is totally depends on you that which type of database server or instances you want to create , here i am choosing MySQL database , i will create a MySQL database or instances.




Now you can see that our MySQL instance has been created so now we have to configure our database,in order to use it ,we will set some network setting, we will create a user, database after that we can use our database instance like we have to set some network settings changes , like we have to allow some users & we have to create a user for our database & then we can use our MySQL instance.


As you can see that i have done some changes in my connections, allowed all the IP address to access my instance, it's not a good practise to do so because of certain security purposes, but since we are doing the testing we can consider this. Now we will create a user for our database so that we can use it.


As you can see that there is new user has been created with the name himalaya, so now we can use the same user for other things.



Now we have done with the user creation part, but to store the data we need a database so we have to create a new database for a user so we will do the same for the database creation.
These are some pre created or existed database but we will create new database for our use.




Now you can see that a new database has been created so now we can use this MySQL instance. We can use the MySQL instance with the help of cloud shell , so we will connect it with the cloud shell.




As you can see that in the above image we had connect our MySQL instances with the help of cloud shell & we had also shown the database of the instances.

Now we have to launched the wordpress on any of the web browser with the help of load balancer that we had use for the worpress pods , so we can connect it the that external ip, that was pending but now if you check it will provide you an external ip just type the ip in browser and your wordpress site will be running on.

Step 6: Connect the SQL database to the web application                                          launched in the Kubernetes cluster.









After this stage i have to publish my post or article on the top of wordpress , now i will show my article or post on the wordpress.




This is all about this article , means how to deploy wordpress as a web server or as a frontend site , how to create a database on the top of GCP cloud , & how to connect both of them .

I hope you like this article, if you have any queries regarding this article or any or error while performing these task, you can contact me .

Thank You so much for reading my article.

Author: Himalaya Sahu (www.linkedin.com/in/himalaya-sahu-1982a2185/)











Comments