DEPLOYMENT OF WORDPRESS ON GKE AND SQL IN DIFFERENT VPC
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 LoadBalancer.
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.
1. PROJECT CREATION:
- We have created a new projects named DeveloperProject and ProdProject
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
- In DeveloperProject, we create VPC as vpcdevproject ( For Wordpress)
-In ProdProject, We Create VPC as vpcprodproject ( For database)
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).
- In DevolperProject, We Create Peering as devpeering as
- In ProdProject, We Create Peering as prodpeering as
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)
To Create a Cluster in one of the VPC of DevolperProject and launch WordPress by using Docker image with the LoadBalancer.
- Launch Wordpress on the top of Kubernetes cluster
Command: gcloud container clusters get-credentials myweb --region asia-southeast1 --project developerproject-288608
But as soon as we expose our pod using LoadBalancer, it is automatically created in GCP. We can give the IP provided by the LoadBalancer 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.
6. CONNECTING DATABASE TO OUR SITE
- Access the WordPress site using the LoadBalancer IP Address as