Deploying WordPress with SQL Server on Google Cloud Platform

Deploying WordPress with SQL Server on Google Cloud Platform

Problem Statement

  1. Create multiple projects namely developer and production
  2. Create a 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

Pre-requisites for practical application:

  1. You should have a GCP account or create a new account before doing this practical.
  2. kubectl should be installed in your system.

STEP 1: Create multiple projects namely developer and production

Create a project named as developer: Go to Projects, add a New Project and give the name developer and create the project.

No alt text provided for this image

Create another project named as the production: Go to projects, add a New Project and give the name production and create the project.


STEP 2: Create a VPC network for both projects

Create a VPC network for developer project: Select the developer project and then go to Home and select the VPC network. Create a VPC network in this project and provide some name and description.

No alt text provided for this image

Create a new subnet in the same VPC network by providing some name and select the region as asia-southeast1 and provide some IP address range(10.0.1.0/24).

No alt text provided for this image

Finally, create the VPC network.

Create a VPC network for the production project: Select the production project and then go to Home and select the VPC network. Create a VPC network in this project and provide some name and description.

No alt text provided for this image

Create a new subnet in the same VPC network by providing some name and select the region as us-east1 and provide some IP address range(10.0.2.0/24).

No alt text provided for this image

Finally, create the VPC network.

STEP 3: Create a link between both the VPC networks using VPC Peering

Create a VPC Peering Network in the developer project: Select the developer project, go to VPC Network and go to VPC Peering and create a VPC Peering Network connection by providing some name and also select your VPC Network created for the developer project.

In Peered VPC network, select for another project because you want to connect to another project. Provide the project ID of the production project and also provide the VPC network name for the production project.

No alt text provided for this image

Finally, create the VPC peering network.

Create a VPC Peering Network in the production project: Select the production project, go to VPC Network and go to VPC Peering and create a VPC Peering Network connection by providing some name and also select your VPC Network created for the production project.

In Peered VPC network, select for another project because you want to connect to another project. Provide the project ID of the developer project and also provide the VPC network name for the developer project.

No alt text provided for this image

Finally, create the VPC peering network.

Remember when both the VPC peering network are created successfully then only the status of the VPC peering network peering becomes Active for both the projects.

STEP 4: Create a Kubernetes Cluster in developer project and launch any web application with the load balancer

Select developer project and go to Kubernetes Engine and select create a cluster.

Select Cluster basics and provide some name as projectk8scluster, select location type as the regional and select region as asia-southeast1, tick on the specify default node location and select all the zones and at last select Master version as static and select the default version.

No alt text provided for this image

Go to the default pool and provide some name as default-pool, the version will be selected automatically and the number of nodes as 1 which will launch one node per zone i.e. we have three zones, therefore, three nodes will be launched.

No alt text provided for this image

Go to the nodes under default-pool and select the default image type, select machine type as N1-standard and the boot disk automatically provides 100 GB of storage.

No alt text provided for this image

Go to Networking and select the network as vpc-dev-project which you created in the developer project and also select the subnet created as dev-lab1.

No alt text provided for this image

Finally, create the cluster.

Then, go to the main page of the Kubernetes Engine and there we can see the cluster and select the cluster and click on connect. This will provide a command through which we can connect with the cluster in the local system.

No alt text provided for this image

7. Run the command and this will allow you to connect with the GKE cluster and perform operations.

8. Launch the web application on top of Kubernetes cluster with Load Balancer by running the following commands:

$ kubectl get all
$ kubectl create deployment wordpress-app --image=wordpress
$ kubectl get pods -o wide
$ kubectl expose deployment wordpress-app --type=LoadBalancer --port=80
$ kubectl get services
$ kubectl get all

No alt text provided for this image

Now our web application WordPress is successfully launched and we can connect with the web application by running the external IP of the service of the deployment.

No alt text provided for this image

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

Select the production project and go to Databases in Home and select SQL. Create a SQL instance and select Choose MySQL

No alt text provided for this image

Provide some instance ID as project-db, give some password for the root account, select the region as us-east1 and select any zone under Location and select some DB version(MYSQL 5.7) and create the SQL instance.

No alt text provided for this image

After SQL instance is created go to Connections and inside the Authorized network, add network by providing some name and the Network as 0.0.0.0/0 which will allow all the IP’s to connect with the instance and at last Save the changes.

No alt text provided for this image

Create a database by going to the databases in the SQL instance and create a database by providing the name as proddb and create.

No alt text provided for this image

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

Run the external IP of the WordPress application created as the deployment and start the installation of WordPress by connecting with MySQL.

  • Provide the same name of the database created in the above step
  • Provide Username as root and Password which you provided while creating the SQL instance
  • Provide the Database host as the Public IP of the SQL instance and Submit
No alt text provided for this image

Now WordPress is successfully connected with the MySQL instance and now provide the Site title, Username and Password for WordPress and your email and finally Install the WordPress.

No alt text provided for this image

After WordPress is installed you can see a login page, log in with the username and password provided for the WordPress at the time of installation and now you can see the dashboard of the application.

No alt text provided for this image

Now you can create any web page or posts or anything you like and it will store the data in the MySQL instance database.

No alt text provided for this image
No alt text provided for this image

Now our WordPress application running on top of GKE in one VPC network in asia-southeast1 region is successfully connected with the SQL instance running in another VPC Network in us-east1 region.

Thank you for reading my article. I hope it will help you understand the concepts worked on. If any improvement required, please let me know.



poonam dinshaw

Mentor - Head Held High's (Bengaluru) Changemaker - Save the Destitute Foundation, Srinagar, J&K

4 年

Cheers....!

回复

要查看或添加评论,请登录

Shubhankar Thapliyal的更多文章

  • Netflix: An AWS Case Study

    Netflix: An AWS Case Study

    Netflix is one of the Biggest customer of AWS and it uses AWS for nearly all its computing and storage needs, including…

  • Configuring Load Balancer on AWS using Ansible with dynamic inventory!

    Configuring Load Balancer on AWS using Ansible with dynamic inventory!

    Task To Be Done: Provision EC2 instances using ansible. Retrieve IP Addresses of instances using the dynamic inventory…

    2 条评论
  • 2 Days Workshop on GCP by LinuxWorld

    2 Days Workshop on GCP by LinuxWorld

    Recently, I finished a 2 day long GCP(Google Cloud Platform) workshop with the guidance of Mr. Vimal Daga.

  • Launching An EC2 Instance On AWS Using Ansible

    Launching An EC2 Instance On AWS Using Ansible

    Hello guys, I'm back with another article. In this article,we'll do the following task: Launch an AWS instance with the…

  • Configuring Docker With Ansible(RH294)

    Configuring Docker With Ansible(RH294)

    Let's write an Ansible PlayBook where we will perform the following actions in managed nodes by using an Ansible…

    2 条评论

社区洞察

其他会员也浏览了