Launching a web app on top of GCP , by integrating multiple services.
In this article we are going to see how to launch wordpress on gcp by using multiple managed services of gcp.
What is Google Cloud?
Google’s cloud platform provides a reliable and highly scalable cloud computing services to its users. These services help clients compute and store data, and help developers build, test, and deploy apps. Google cloud covers application, storage, and cloud computing services for backend, mobile, and web solutions using the internet. More than four million apps trust and use this platform.
Task Details..
- .Create multiple environments namely developer and production for that,
- Create VPC network for both the environments .
- Create a link between both the VPC networks using VPC Peering.
- Create a Kubernetes Cluster in developer environment and launch any web application with the Load balancer.
- Create a SQL server in the production environment and create a database.
- Connect the SQL database to the web application launched in the Kubernetes cluster.
Let's start building ..the task.
Creating VPCs..
Virtual Private Cloud (VPC)????
“A Virtual Private Cloud (VPC) is a global private isolated virtual network partition that provides managed networking functionality for your Google Cloud Platform (GCP) resources.”
Now, first go to GCP console and then open the services list and click on VPC Network, now you will be landed to this page...
Click on Create VPC Network and follow steps below mentioned ...
In this task i'm going to create two vpcs one for developer environment and the other for production environment in Singapore(asia-southeast1) and LosAngeles (US-west2) respectively with one subnet in each.
Vpc for developer environment:
Vpc for production environment:
Thus,both vpcs are created successfully..
VPC Peering...between above two Vpcs..
What is VPC peering and how it works..?
Google Cloud VPC Network Peering allows internal IP address connectivity across two Virtual Private Cloud (VPC) networks regardless of whether they belong to the same project or the same organization.
VPC Network Peering enables you to connect VPC networks so that workloads in different VPC networks can communicate internally. Traffic stays within Google's network and doesn't traverse the public internet.
For this first go VPC network and then select vpc peering then follow the steps mentioned in below..
Now, click on create connection..
Let's create the connection from dev-vpc first to prod-env:
But if you see the status of connection it will be inactive ..
If you want it actively connect to the other vpc ,we should also create the same as above in that vpc to accept connection.Let's see what happens..
And now if you see , the connection is activated..
Creating a Kubernetes cluster and launching a web app ..in dev env.
What is Kubernetes?????
Kubernetes is a portable, extensible, open-source platform for managing containerized workloads and services, that facilitates both declarative configuration and automation. It has a large, rapidly growing ecosystem.
What is GKE?
Google Kubernetes Engine or "GKE" is a Google-managed Kubernetes environment. GKE is a fully managed experience; it handles the management/upgrading of the Kubernetes cluster master as well as autoscaling of "nodes" through "node pool" templates. Through GKE, your Kubernetes deployments will have first-class support for GCP IAM identities, built-in configuration of high-availability and secured clusters, as well as native access to GCP's networking features such as load balancers.
Let's create a kubernetes cluster on GCP using Google Kubernetes Engine (GKE):
For this first click on GKE and cluster from selection..then you will be landed here..
Now click on create cluster..and follow the same as below,
Now finally configure the network details ,i.e vpc and subnet where the cluster to be launched....here i'm launching in the developer vpc ..
Now, if use see the cluster has been successfully created in singapore region..
Now how to use this cluster ?????? - For this we need to setup the kubernetes client using the package called "kubectl".Here I'm using my cloud shell itself as kubernetes client and hence i setup kubectl in it...
Setting up K8's client within the cloud shell..
For this we need to follow three simple commands or steps as below , then everything is done.
- Download the latest release with the command:
curl -LO "https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl"
2. Make the kubectl binary executable.
chmod +x ./kubectl
3. Move the binary in to your PATH.
sudo mv ./kubectl /usr/local/bin/kubectl
That's done ...confirm it by verifying the version of kubernetes using the cmd:
kubectl version --client
Using this link..you can find the steps to setup kubectl in client...
Here it is..done.
Now let's connect to cluster using cloud shell..
For this , you have to go to clusters and click on connect on the cluster you created , it will popup a window like this:
Copy the command line access link and paste it in the cloud shell to register the cluster with kubectl and to verify run some commands as follows to check the nodes present in the cluster.
Now, let's launch the web app using kubernetes..
Here, i'm using the wordpress as webapp and using it's docker image i'm launching a pod of wordpress using deployment also expose it outside world using the internal loadbalanacer of the GCP..
Let's see how it works..before that if we see there is no load balancer created priorily..but after we expose ..a load balancer is created automatically internally.
Let's create the deployment and expose it.
From the commands itself..you know that a pod has been created and the service with type Load Balancer has been created..
Now,using the load balancer Ip we can connect to the wordpress site...but before going to that we know that wordpress being a frontend requires the backend to store all its data.For that we will create a MySql database using SQL service provided by the GCP.
Creating MySql database for wordpress using SQL service ...
For this , firstly we need to go for sql service and create an instance ..follows the steps mentioned..
Now, im going to configure instance details and creating it in the region LosAngeles...also setting the root password too.
Click on create then it will be created ..as shown below.
Now , if you try to use the database it won't work ..why because we haven't set any firewall rule so that someone should use this database.We can create the firewall rule as follows..for this we first go to conections and apply as below.
Now save the changes..and next we have to create a database for the wordpress ..
For this first go to the databases and click on create new database...provide the name and save it..see below.
That's it everything has been done perfect and now we use the loadbalancer ip to connect to the Wordpress site and use the Mysql instance ip and database created as backend host configuration details ...
Let's start with configuring the wordpress site..
Finally After login to the Site ...create a sample page of your choice ..here is mine..??????
That's all for the task ...Thanks for reading...??
Any queries or suggestions..connect me on Linkedin ..Thank you.