GOOGLE CLOUD PLATFORM (GCP) WITH KUBERNETES
Hey! folks here comes a new blog with an amazing integration of GCP with Kubernetes. Here you will be getting the connection between the production and developer from one part to another part of the globe. Its a great concept as you will be sitting in one region and your instance will be launched and will be connected to another region of the world.
Before constructing the wonderful setup let me introduce you with some terminologies and most important the technology and platform used.
- GOOGLE CLOUD PLATFORM(GCP) => Google Cloud Platform is a set of Computing, Networking, Storage, Big Data, Machine Learning and Management services provided by Google that runs on the same Cloud infrastructure that Google uses internally for its end-user products, such as Google Search, Gmail, Google Photos and YouTube.
- GCP SERVICES => The service list of GCP is so humongous and the features it include is just amazing. I will be listing only some of the services here which are the majorly and common used services.
- Compute
- Networking
- Storage and Databases
- Big Data
- Machine Learning
- Identity & Security
- Management and Developer Tools
3. CLOUD COMPUTING => Cloud computing is the on-demand delivery of compute power, database storage, applications, and other IT resources through a cloud services platform via the internet with pay-as-you-go pricing. It is the use of remote servers on the internet to store, manage and process data rather than a local server or your personal computer.
4. KUBERNETES(K8s) => Firstly it is denoted as K8s. It is a container management system developed in the Google platform. The purpose of kubernetes is to manage a containerized application in various types of Physical, virtual, and cloud environments. Google kubernetes is a highly flexible container tool to deliver even complex applications, consistently. Applications run on clusters of hundreds to thousands of individual servers.
Features of Kubernetes :
- Automated Scheduling.
- Self-Healing Capabilities.
- Automated rollouts & rollback.
- Horizontal Scaling & Load Balancing.
- Offers environment consistency for development, testing, and production.
- Infrastructure is loosely coupled to each component can act as a separate unit.
5. VPC => Firstly VPC stands for Virtual Private Cloud. It enables you to build a virtual network within the cloud not any VPNs, hardware or physical data centers required. You can define your own network space, and control how your network and the resources inside your network are exposed to the Internet.
6. VPC NETWORK PEERING => Google Cloud VPC Network Peering allows Internal or Private 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.
7. SUBNETS => A subnet or subnetwork is a segmented piece of a larger network. More specifically, subnets are a logical partition of an IP network into multiple, smaller network segments. The Internet Protocol (IP) is the method for sending data from one computer to another over the internet.
So, lets go for it!! Just follow the steps and and the beautiful and amazing setup will be infront of you.
STEP-1 - Login to your Google Account and if you do not have the account you can make one. You can visit the respected link to register yourself or for making the Google Cloud Platform.
Just fulfil the requirements and you are ready to work upon the platform. Guys before moving forward one interesting thing about GCP is that you will be $300 credit free from Google.(The only condition is that you should have the credit card)
For those who do not have credit card
You can go to the services of Google that is Google Free Lab known as QWIKLABS. But one lab has a time period of 40 Minutes and each lab cost a credit.You can access it from the link given below.
You can setup the QWIKLABS with my blog mentioned below.
STEP-2 After you login you will find the GCP console and in that just go to the Compute Engine => VM Instances as shown below.
You will be on the screen shown below. Now click on the Create button.
STEP-2 You will be landed on the page as shown below. Here we are going to create the instance in the selected region.(I am launching one instance in the singapore region i.e. asia-southeast 1 in GCP).
Now choose for the region you want to launch your instance as shown below.
After that choose for the operating system you want to work on (Here I am choosing for the Centos OS) . For doing that just click on the Change as shown below.
Now choose for the Centos here
Choose for the stable version of the OS i.e. Centos 7
After all the get done click on the Create.
You will now see that your OS is now created at it will be as shown below.
Now copy the External or Public IP of your instance and paste it on the browser as shown below. You will see this output.
It is because your Instance do not have any Firewall settings so that it can be accessed by any method.
STEP-3 We will now create the Firewall for the Instance created through which we can access it.
For creating this Go to Networking => VPC network => Firewall as shown below.
You will be landed on this page.
Now click on the Create Firewall Rule as shown below.
Now name your firewall as shown below.
Choose for the targets that actually means whom you want to cross the firewall.
Now write the Ingress (you want to come in or access your os) Rule and 0.0.0.0/0 means every IP address can access your system or you can give some particular IP and choose for the protocol TCP at port 80 so that it can be accessed through the browser as shown below.
Now click on Create after doing all the steps shown above.
Now you will see that your firewall will be created.
STEP-4 Now let us go to the create the VPC so that a network communication can be setup.
For setting that go to the VPC Networks as shown below.
After clicking this you will be landed to the page. Just click on the Create the VPC Network as shown below.
Now name your VPC Network as shown below.
Now let us create the Subnets which is the private path within the Google Cloud.
Now let us choose for the region we have our instance in Singapore region so we will setup in the same region.
Now we will provide an IP address range to it as shown below. Actually for the type of Network connection we have classes and ranges of IP and Subnets.
Now after all the steps shown above just click on the create button as shown below.
After clicking create you will be landed to a window. Just scroll down and you will see a VPC is created as shown below.
Now go back again to your VM Instances by
Compute Engine => VM Instanes as shown below.
STEP-5 Setting up the webserver in the OS
To do the mentioned just access the Instance created through SSH as shown here.
The screen will look alike as shown here.
Now you will be seeing the cmd type screen but actually that is your OS (Centos 7). Now just write the command given and shown below.
sudo su - root => This command gives you the power of the root user that is actually considered as the Administrator of the Operating System(OS).
Centos 7 is alike RedHat Linux so who has a knowledge of Linux Shell commands they can try some commands or if don’t know you can try for these simple commands shown below.
Now for setting up the webserver you have to first install HTTPD.
For this use yum install httpd as shown below.
If this output comes it is successfully installed.
After this go to the folder i.e. var/www/html through this command
cd /var/www/html => It is the folder where every file created will be shown on the web.
Make a file with vim <space>filename with extension html/php.
Although I have made a file with the extension html and index.html is the name of the default file(If you make a file with name index.html there will be no requirement to give the name of the file in the web browser.)
Make the file through the command vim index.html write the code there and if you want to save it just press Esc and write :wq. It will be automatically saved and you will return to the CLI(Command Line Interface) of your OS.
Sample is shown below.
After saving the file restart the service of HTTP by the command
systemctl restart httpd as shown below.
Now go to your instance , copy your External IP as done before and paste it on the browser and you will see the output as shown below.
STEP-6 Now let us create a one more instance in another region to setup the Peering Network.
I am launching this instance in the South Carolina - USA i.e. us east 1 in GCP. You may launch it in another region accordingly.
It will be done as launched the above instance in Singapore Region
Name your instance as shown below.
Choose for the Operating System as shown below.
I am choosing for the Centos 7 here.
Again the Stable version for the OS.
Click on Create as shown below.
Instance is now created.
STEP-7 Now we will be creating the Firewall for accessing the instance as done before and shown below.
Now create new firewall rule.
Name the Firewall.
Set the Targets to get enter in the OS.
Set the IP Ranges.
Set the Protocols for the permissions for IP addresses.
Click on Create.
The firewall is now created.
STEP-8 Now let me make the VPC network for this Instance.
For creating this go to the VPC Networks as shown below.
Name Your VPC.
Make a Subnet for it.
Click on Create Button.
Your VPC is now created. (Just scroll down the window)
STEP-9 Setting up the web server for Instance launched in the US region.
For doing the above mentioned just go back to your Instance through
Compute Engine => VM Instances
You will be landed to the window shown below and just try to login it with SSH.
Enter the Instance , go to the root through the command
sudo su - root
Now Install HTTP in it through the command
yum install httpd as shown below.
If this output appears it is successfully installed.
Now go to the folder var/www/html through the command
cd /var/www/html
Make a file and write the code in the file and save the file by
- Press Esc
- :wq
It is shown below.
Now after saving the file restart your HTTP Server by using the command
systemctl restart httpd
Now copy the External IP of your US-Instance and paste it to the browser as shown here.
Now both the Instances are setup and now we need to Peer those two instances. It is like we will create our own network and path to communicate between these two Instances without messing with the traffic of the cloud.
STEP-10 Now let us go to the VPC Peering service provided by GCP.
For this go to the Network Section in which
VPC Networks => VPC Network Peering as shown below.
You will be landed to a page and then click on the Create Connection as shown below.
Then click on Continue as shown here.
Now ,
- Name the connection.
- Choose for Singapore region VPC Network.
- Choose for US region VPC Network.
- Click on Create Button.
All the steps are shown below.
You will be landed to the window shown below and will see the inactive status of the connection.
It is because the connection is done from only one side the other also should be interested in connecting the same.
Once the other Instance also connects the network it will become active automatically.
So, for doing that Click on Create Peering Connection as shown below.
Now ,
- Name the connection.
- Choose for US region VPC Network.
- Choose for Singapore region VPC Network.
- Click on Create Button.
All the steps are shown below.
Once you have done the required you will be landed to a page which will show two connections with active status as shown below.
Now for checking that connection successful go back to your instances in VM Instances in Compute Engine.
The highlighted IP Address shown below is the Private or Internal IP Address of your instance. It comes into use when you want to connect your instance within the single or same network.
Try to access your Singapore region instance through SSH and then copy the Internal or Private IP of the US region Instance and try to ping it as shown below.
Now do the same with the US located Instance i.e. try to access the US region Instance with the SSH and copy the Internal IP Address of the Singapore region Instance and try to ping it in the US Region Instance as shown below.
If you see the following output as shown above you have successfully created the VPC Peering Network.
It is like you have one team in Singapore and other team in USA and you have created your own network avoiding the traffic of the Google Cloud Platform.
STEP-10 After this wonderful connection let us go for the Integration of this network with the Kubernetes using the service of GCP i.e. Kubernetes Engine.
Now to achieve the required firstly go to the Kubernetes Engine and then to the Clusters as shown below.
You will be landed to a page. Click on the Create Cluster there as shown below.
You will be landed to this page. Just click on the default pool.
Now you will be at the page shown below.
Now,
- Name the Node Pool.
- Choose for the Node Version.
- No. of nodes you want to deploy.
as shown below.
But before that let me explain you the following:
Guys! you need to understand that here node means the one system in a zone and there is one Master node and two slave nodes. So, you need to decide that how many nodes you want to launch or deploy.
Let’s say if you launch 3 nodes then all over 9 nodes will be launched because there are 3 zones and if 3 nodes are launched in one Zone or data center it can be calculated as 3*3=9.
As you increase the number of nodes you will need to scale out your computing power.
I am choosing for 1 node here i.e. 1*3=3 nodes in totality.
Now come to the Cluster Basics and do the required configuration and choose for the respective region as shown below.
After doing the required configuration just click on the Create Button.
You will be landed to a page where you will see that your cluster is launched.
STEP-11 Now we will connect it with the Command Prompt of the Computer.
For achieving this we have to first download the Google Cloud SDK.
You can download it from the below link.
Once it get downloaded you need to download you need to download the kubectl at setup it.
You can download and setup it from here.
In your Command Line Prompt write the command to login to your Google Account i.e.
=> gcloud auth login as shown below.
A webpage will automatically open and just allow all and after that at your Command Prompt you will see the output above.
Now come back to the Kubernetes Cluster and Click on the Connect as shown below.
You will see the command that is used to connect the cluster with the CLI. Just copy it and paste it on the Command Prompt as shown below.
Once you do it you will get the output as show below.
You can check it by writing the command
kubectl get nodes as shown below.
You can cross-check it by one more command i.e.
=> kubectl config view
STEP-12 Now go to the SQL Service of the Google Cloud Platform as shown below.
Storage => SQL
Click on the SQL and you will be landed on the page. Just click on the Create Instance there as shown below.
You will be now landed to other page. Choose for the version of SQL i.e. Version 5.6 and click on My SQL as shown below.
Give the name and password for the Instance because it will work as the database so password is required or you can go for no password.
Now choose for the region of the MYSQL instance and click on Show Configuration options as shown below.
Go to Connectivity and Click on ADD NETWORK there as shown.
Set for the following configurations and click on the Done button as shown below.
After it is launched successfully.Just click on the Connect Using Google Shell as shown here.
Just Enter to the command written there and enter the password given while making the instance as shown.
You can create the Database through the command i.e.
create database <database name>;
You can check it by going to the Databases option there on the window as shown.
Once you click it you will be seeing your database will be there.
OR
You can do it through GUI by clicking on the Button Create Database as shown below.
Now you need to name your database and click on Create button as shown below.
STEP-13 Now come to your Command Prompt and create a deployment with the image of WordPress as shown below.
Write the command:
kubectl create deployment <deployment name> — — image = wordpress
You can scale it by using the command :
kubectl scale deployment <deployment name> — — replicas=3(you can give your own as per requirement)
as shown below.
You can see the pods through a command i.e.
kubectl get pods
OR
kubectl get pods -o wide as shown below.
STEP-14 Once you have done this you need to expose the deployment which means that you can connect your deployment in the outer world or you will get an External IP.
For this you can use the command:
kubectl expose deployment <deployment name>
— —type=LoadBalancer
— — port = 80 as shown below.
Once you have done that you will see that the Load Balancer will be created in the GCP.
For viewing that you need to go to In GCP GUI
NETWORKING => Network Services => Load balancing as shown below.
You will see a Load Balancer there and just click on the name of the Load Balancer as shown below.
Once you click it you will see your running nodes i.e. 1 node per region.
STEP-15 Now its time to launch and setup this Multi Tier Architecture integrated with Kubernetes and launched within the Google Cloud Platform.
For doing the required you need to go to the Command Prompt and get the External IP so that you can connect with it.
For getting the External IP you can use the command:
kubectl get services as shown below.
Now after doing this just copy the External IP of the LoadBalancer as shown below.
Now paste it in the Browser and then click for Continue as shown below.
Now write the
- Name of the Database given when made.
- Username should be root.
- Give the password of your database.
- External IP of the SQL Instance in GCP.
- Click on Submit.
All the steps are shown below.
If the below page is displayed as shown below then your connection with the database is successful.
Click on Run the Installation button as shown above and you will be landed to the page shown below.
Now
- Set the Title
- Give your Email Id
- Give the Password for the WordPress now.
- Press Install WordPress.
After doing the required you will be landed to this page shown below.
Login Here with your Email ID and Password set for WordPress as shown above and then you will reach to the DASHBOARD of the WordPress shown below.
The whole architecture can be visualized on the Map which is shown below.
The map actually tells us that the WordPress site or Load Balancer is in Singapore (asia-southeast 1) and the database is in USA South Calonia(us-central 1) and they both are connected and are ever ready to communicate beween each other,can retrieve and store the data in MYSQL.
Thanks a lot !!
Hope you enjoyed creating this wonderful setup.