Hybrid Cloud Setup on GCP

Hybrid Cloud Setup on GCP

What is a hybrid cloud?

In a fast-moving and agile world, we want to have resources with no limits, they have to be smart enough to handle the load and easily scalable. For this, we have IaaS (Infrastructure as a Service), providers. Google provides such a facility it's called Google Cloud Platform (GCP). Now, hearing the word cloud we think it's a collection of servers that are rented to the users. It's not completely like that, the cloud is just a program (software) which is a collection of so many drivers which provides a layer over the resources (abstraction). This layer is made interactive and user friendly by making a UI over it. This UI is what we see as GCP, AWS, Azure, Alibaba Cloud, Openstack, and many more.

One more technology which we need by default for fast time to market and managing the infrastructure is called container management and over it, we need a container orchestration engine. Some examples are Kubernetes Cluster and Openshift Cluster respectively. Configuring and managing these are also complex. We need resources again for deploying this. So service providers also provide PaaS (Platform as a Service), this handles our Kubernetes dynamically.

Finally, having PaaS on IaaS is called a hybrid setup and if we have these services from a cloud service it's called Hybrid Cloud.

What we will perform?

  1. Create two projects on GCP as two different team managing frontend and backend.
  2. Creating VPC on both the project and peering them.
  3. On the backend VPC, we will set the MySql database using SQL service.
  4. On the frontend VPC, we will set the Kubernetes Cluster and then deploy WordPress on top of it connecting it with backend.

Creating two projects and VPC inside them

No alt text provided for this image
gcloud projects frontend-wordpress --name=wpfrontend

This will create a project named wpfrontend, here remember that the ID should be unique i.e. frontend-wp must be unique.

Similarly, we created a backend project.

gcloud projects backend-wordpressmysql --name=mysqlbackend
No alt text provided for this image
gcloud projects list

Command to list the projects in the account. Here we will see how to make VPC inside the project. So first we need to switch into the project, for this the command is:

gcloud config set project <project name>

Then we will run the command for creating VPC inside the project.

gcloud compute networks create frontend --bgp-routing-mode=regional --description=wpfrontend --subnet-mode=custom --project frontend-wordpress

This will ask you to enable the API where you have to give "y" as yes.

The next step is we need to connect the project with the billing account or else it won't create any resources further.

gcloud alpha billing accounts list

gcloud is the command utility for GCP it has versions of it and per each version, they have different commands and ability to do things. Here we used the alpha which has capabilities to get the billing accounts.

gcloud alpha billing accounts projects link frontend-wordpress --billing-account=<ID which we will get from the previous command>

This will link our project to the billing account. Now we are good to go for using the resources.

Similarly, we will create a backend project and VPC inside it and link it.

No alt text provided for this image

Now, here you might see an error, this is because we have reached a limit of associating the project to the billing account. Now, we need to write to the GCP team to increase the limit. But, instead, you can disassociate other projects from the billing account.

After creating the VPC they will tell us to even mak security groups or firewalls for each project which is mandatory. It's good that they have given us the command to do that. But we will make a minor change in it. For the frontend, we need SSH and HTTP (WordPress) enabled, and for the backend only 3306 (MySQL).

Note: We need to do this for both the project hence switching between the project is a necessary thing.

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

Peering(establishing a connection between both the projects)

No alt text provided for this image

Peering means establishing a connection between the projects and the VPC. This needs to be done from both the side. So we need to first do this on one side and then on the other too.

No alt text provided for this image

Command to do the peering is:

gcloud compute networks peerings create <name> --network <network name> --peer-project <project where to peer> --peer-network <network where to peer in the project> --import-custom-routes --export-custom-routes

Creating MySQL database instance on GCP SQL service

No alt text provided for this image

Click SQL

No alt text provided for this image

Click on create an instance.

No alt text provided for this image

Choose MySQL

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

Configure as shown and press create.

Add an user to it.

No alt text provided for this image

Go to users

No alt text provided for this image

Create user

No alt text provided for this image

Set a username and password.

Create a database inside it.

No alt text provided for this image

Command to create a database inside an SQL instance is.

gcloud sql databases create <name> --instance=<sql instance name>

We can verify it using the cloud shell from the console.

No alt text provided for this image


Creating a Kubernetes Cluster on GCP

No alt text provided for this image

Go to clusters

No alt text provided for this image

Click create a cluster.

No alt text provided for this image

Configure as shown.

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

Click on create.

No alt text provided for this image

We will see one cluster created. Click on connect and a pop-up will come which will give a command which we need to run either in cloud shell or on the local terminal if we have kubectl.exe

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

Now we can see 3 nodes that are on GCP GKE Cluster.

No alt text provided for this image

Creating WordPress Deployment

No alt text provided for this image
kubectl create deployment <deployment name> --image=wordpress

To create a deployment.

kubectl expose deploy <deployment name> --type=LoadBalancer --port=80

To create LoadBalancer.

Finally, we will get the IP or say the service where WordPress is running.

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

Thank you for reading this article! Feel free to connect and ask queries if any!


To view or add a comment, sign in

Others also viewed

Explore topics