Deployment of WordPress on Google Cloud Platform ( GCP) with VPC and Kubernetes Integration
This blog contains the following task process and details :
1. Create one project.
2. Create two VPC networks in the project.
3. Create a link between both the VPC networks using VPC Peering.
4. Create a Kubernetes Cluster in one of the VPC and launch WordPress by using Docker image with the Load Balancer.
5. Create a SQL server in another VPC and create a database.
6. Connect the SQL database to the web application launched in the Kubernetes cluster.
Wait, why cloud computing?
→provides with various resources and services, is a pay as you use model.
→you no longer need to pay wages for expert staff
→your energy consumption costs may be reduced
→there are fewer time delays.
→ your business can scale up or scale down your operation and storage needs quickly to suit your situation
and much more….
1. Project Creation:
We have created a new project named GCPtask
2. Creation of the two VPC networks
What is VPC?
Virtual Private Cloud (VPC) enables us to launch resources into a virtual network that you’ve defined. It resembles a traditional network that you’d operate in your own data center, along with the benefits of GCP. We do not require to use public internet and can use the private network of GCP for performing tasks.
Created two VPC networks — vpcwp ( For Wordpress) and vpcdb ( For database).
We can see both the VPC networks on the dashboard
3. VPC Peering
What is VPC Peering?
Creating a connection between different VPC is known as VPC Peering in simple terms. It allows internal IP connectivity across two VPC networks regardless of whether they belong to the same project or the same organization.
NOTE: VPC Peering has to be established from both the sides ( both the networks).
We can see the connection has been established from both the sides and is active( In case any one of them is being displayed as inactive, that means the two-way connection has not been done)
4. Kubernetes Cluster
What is Kubernetes?
Kubernetes is basically a management tool for containers ( Docker, Podman, Crio etc) . Some requirements can be solved by different containers. But what if due to some reason the environment goes down? We can’t monitor it manually. We need some intelligent tool for this. Kubernetes does that. It does auto-scaling and also has inbuilt load balancers. Some of the terms related to it:
→ Node: Kubernetes runs your workload by placing containers into Pods to run on Nodes. A node may be a virtual or physical machine, depending on the cluster. Each node contains the services necessary to run pods, managed by the control plane. Kubernetes is a master-slave type of architecture with certain components.
→Pod: A pod is a collection of containers and its storage inside a node of Kubernetes cluster. Each pod in Kubernetes is assigned a unique Pod IP address within the cluster, which allows applications to use ports without the risk of conflict
We have created a Kubernetes cluster using GKE ( Google Kubernetes Engine)
We have specified the number of nodes we want in each zone
The architecture of our node image
We can have two types of location/center: Zonal ( launches all nodes in one zone) and Regional ( distributes among different zones)
We have used regional locations
We have created our cluster in the vpcwp network as we plan to launch WordPress here.
We can see our cluster has been created and the three instances have been launched:
Launch Wordpress on the top of Kubernetes cluster
We need to connect to the cluster using the Google Cloud Shell. For that, we need to run the following command in the shell.
We have used the image of Docker and created the deployment for WordPress:
After this, a pod will be created for WordPress. But what if the pod gets deleted or there is high traffic? Replicas and LoadBalancers are used to handle it:
We can see initially there aren’t any load balancers created on our GCP
But as soon as we expose our pod using LoadBalancer, it is automatically created in GCP. We can give the IP provided by the Load Balancer to our clients to access the site.
5. Creating SQL server in another VPC
Why not just launch our Database server in the node pool using cluster?
→ We know a database is the most critical part of any business. We will have to manage everything, also keeping high security into consideration. So, instead of that, we can use the managed service by GCP for creating and managing our critical databases. GCP manages everything related to security, resources, scaling etc. We can create our front end using an instance and connect it to the database service.
Creation of MySQL database:
In the configuration options, we have connected to the private IP as we want to create it in our vpcdb network
Creating a new user and database for our WordPress site:
To connect to our database, we have to run the following command in the shell:
mysql -h <IP of your database server> -u <username> -p
Enter the password given for the user, we’ll get the SQL terminal. We can see that for our WordPress database, there are no tables available initially.
6. Connecting Database to our site
Access the WordPress site using the LoadBalancer IP Address.
Enter the details to connect to the database:
The MySQL database has been attached now. We can use WordPress to create our blogs!!!
ALso, if we now check our database, a table would have been created:
Thank you!
For any queries, connect with me on Linkedln.