Launch an Application using Kubernetes on Google Cloud.
Nimish Agarwal
Magento 2 Developer | Shopify Developer | Web Developer | Online Security Advisor | Cyber security Researcher | Tech Writter | Former GPCSSI Intern.
What is cloud computing?
Cloud computing is the on-demand availability of computer system resources, especially data storage and computing power, without direct active management by the user. The term is generally used to describe data centers available to many users over the Internet.
There are two types cloud:- 1. Public Cloud 2. Private Cloud
1. Public Cloud:-
A public cloud is a type of computing in which a service provider makes resources available to the public via the internet. Public cloud allows for scalability and resource sharing that would not otherwise be possible for a single organization to achieve. For example:- AWS, GCP, Azure, etc.
2. Private Cloud:-
Private cloud is a computing model that offers a proprietary environment dedicated to a single business entity. As with other types of cloud computing environments, private cloud provides extended, virtualized computing resources via physical components stored on-premises or at a vendor's datacenter. For example:- Openstack, etc.
Now, we will launch an application using Kubernetes on Google Cloud.
So let's get started...
Step1:- First, we have to Click on My First Project on GCP.
Step 2:- Click on NEW PROJECT to create a new project on GCP Cloud.
Step 3:- Write Project name and if you want then you can edit Project ID as well by clicking on EDIT option, then click on CREATE button.
Step 4:- Similarly, create one more project for production and enable Compute Engine API on both projects.
Step 5:- Next, we have to create a VPC in both the projects. The steps for the same are as follows:
- Click on CREATE VPC NETWORK
- Fill the Name of VPC, Name of New Subnet and IP address range and also select the Region according to your choice.
- Similarly, create one more VPC in production project.
Step 6:- Now, we have to link both the VPC using VPC Peering. The steps for the same are as follows:
- Click on CREATE PEERING CONNECTION
- Click on CONTINUE button.
- Fill the Name of Peering Connection, select the Network from which you want to peer this VPC and then, select the VPC Network which you want to peer is in the current project or in other and also fill the Project ID as well as give the VPC Network Name and click on CREATE button.
- Similarly, we have to create the peering connection from the production project as well otherwise it will remain inactive.
Step 7:- Now, we have to create a Kubernetes Cluster in developer project. The step for the same are as follows:-
- Click on Create Cluster button.
- Fill the Name of Cluster, choose Location type and Master Version and click on CREATE button.
- Now, fill the details for NODE POOLS i.e., Name of the Pool, select Node version and size and specify node locations then, click on CREATE button.
- Next, select the Image type, Series, Machine type, Boot disk type and size and also choose Machine family and then, click on CREATE button.
- Now fill the Networking part, select Network, Node subnet, enable the traffic and also set the limit of pods per node and click on CREATE button.
Our Kubernetes Cluster is ready...
Step 8:- Next, we have to install SDK for Google Cloud.
Step 9:- Now, we have to install kubectl and configure it. You can go through the following link for the same:-
Step 10:- Now, we will deploy an OS with the desired image, H ere, I am using the image whih has WordPress already configured in it. You can configure it by your own. The command for deployment is as follows:-
kubectl.exe create deployment myweb --image = vimal13/apache-webserver-php
- Next, scale it with the following command:-
kubectl.exe scale deployment myweb --replicas=5
- Now, expose it with the following command:-
kubectl.exe expose deployment myweb --type=LoadBalancer --port=80
Load Balancer is created successfully...
Step 11:- Now, we have to create a SQL server in the production project and also have to create a database. The steps for the same are as follows:-
- Click on CREATE INSTANCE
- Now, choose the database engine. Here, I am choosing MySQL, you can choose according to your requirement.
- Now, fill the details like Instance ID, set Root Password, and also choose Region and Database version.
- If you want to edit anything, then you can edit.
- Now, create the database by filling Database Name and clicking on CREATE button as shown below.
Step 12:- Now, we have to connect the database to the web application launched in the Kubernetes Cluster. Run the following command:-
kubectl.exe get services