Project Deployment on Google Cloud Platform using Kubernetes

Project Deployment on Google Cloud Platform using Kubernetes

Task Details:

  1. Create multiple projects for Development and Production
  2. Create VPC network for both the projects
  3. Create a link between both the VPC networks using VPC Peering
  4. Create a Kubernetes Cluster in Development project and launch any web application with the Load balancer
  5. Create an SQL server in the production project and create a database
  6. Connect the SQL database to the web application launched in the Kubernetes cluster

This task consists of following steps for deployment of a WordPress application and Database in two different project clusters(i.e. Development and Production) using Google Cloud Platform and Google Kubernetes Engine .

Steps:

1. Creating Projects for Development and Production environment

In this step, two projects for Development an Production environment has been created. Upon successful creation, the projects will be accessible through Google Cloud Platform console.

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


2. Configuring Google Cloud CLI and linking it with IAM

List of projects can be viewed through Command Line Interface using the below command.

gcloud projects list


No alt text provided for this image

For using gcloud CLI, to configure Kubernetes on GCP, Beta Commands add-on needs to be installed.

No alt text provided for this image


3. Enabling billing for the projects

Billing needs to be enabled for using GCP services for both the projects.

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

4. Creating VPC for the Development and Production projects

For configuring Virtual Private Cloud network, to establish secure connection between services, below commands can be run for both Development and Production projects.

Development:

Creating Network:

gcloud compute networks create dev --project=npdevenv --description=DevelopmentVPCNetwork --subnet-mode=custom --bgp-routing-mode=regional


No alt text provided for this image

Defining Custom subnet IP range:

gcloud compute networks create dev --project=npdevenv --description=DevelopmentVPCNetwork --subnet-mode=custom --bgp-routing-mode=regional


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

Production:

Creating Network:

gcloud compute networks create prod --project=npprodenv --description=ProductionVPCNetwork --subnet-mode=custom --bgp-routing-mode=regional


No alt text provided for this image

Defining Custom Subnet IP range:

gcloud compute networks subnets create subnetprodvpc --project=npprodenv --range=110.0.20.0/24 --network=prod --region=us-central1


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



5. Setting VPC Firewall for Development and Production Projects

Allowing access for communication requires setting up network Ingress-Egress Firewall rules for TCP and other network protocols. It can be done using below command.

Development:

cloud compute --project=npdevenv firewall-rules create devfirewall --description=DevFirewall --direction=INGRESS --network=dev --action=ALLOW --rules=tcp:22,icmp


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

Production:

gcloud compute --project=npprodenv firewall-rules create prodfirewall --description=ProdFirewall --direction=INGRESS --network=prod --action=ALLOW --rules=tcp:22,icmp


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


7. VPC Network Peering between Development and Production environment

VPC Network Peering is required to enable communication between two different VPCs. Here enabling bi-directional network peering for the projects will allow Development environment to communicate with Production environment and vice versa.

gcloud compute --project=npprodenv networks peerings create proddevvpcnetpeering --network=prod --peer-network=dev --peer-project=npdevenv
No alt text provided for this image
No alt text provided for this image



gcloud compute --project=npdevenv networks peerings create devprodvpcnetpeering --network=dev --peer-network=prod --peer-project=npprodenv
No alt text provided for this image
No alt text provided for this image



8. MySQL Database Setup in Production Environment

MySQL Database has been setup in Production project to be used as a data source by the Web application on Development project using below command.

gcloud sql instances create mysql --project=npprodenv --database-version=MYSQL_5_7 --storage-type=HDD --tier=db-n1-standard-1 --region=us-central1 --root-password=xyz987


No alt text provided for this image


No alt text provided for this image


No alt text provided for this image


No alt text provided for this image

9. Deploying Kubernetes Engine on GCP in Development Environment

For creating Web application on Development environment, as a load balanced and fault tolerant deployment, Google Kubernetes Engine can be used.

gcloud beta container --project "npdevenv" clusters create "kubernetescluster" --region "asia-northeast1" --no-enable-basic-auth --machine-type "n1-standard-1" --image-type "COS" --disk-type "pd-standard" --disk-size "100" --metadata disable-legacy-endpoints=true --scopes "https://www.googleapis.com/auth/devstorage.read_only","https://www.googleapis.com/auth/logging.write","https://www.googleapis.com/auth/monitoring","https://www.googleapis.com/auth/servicecontrol","https://www.googleapis.com/auth/service.management.readonly","https://www.googleapis.com/auth/trace.append" --num-nodes "1" --enable-stackdriver-kubernetes --enable-ip-alias --network "projects/npdevenv/global/networks/default" --subnetwork "projects/npdevenv/regions/asia-northeast1/subnetworks/default" --default-max-pods-per-node "110" --no-enable-master-authorized-networks --addons HorizontalPodAutoscaling,HttpLoadBalancing --enable-autoupgrade --enable-autorepair --max-surge-upgrade 1 --max-unavailable-upgrade 0


No alt text provided for this image


No alt text provided for this image

Once Kubernetes clusters are setup, distributed compute can be verified.

No alt text provided for this image

For controlling Kubernetes clusters using CLI, below command should be executed.

gcloud container clusters get-credentials kubernetescluster --project npdevenv --region asia-northeast
No alt text provided for this image

Nodes created can be verified using below command and on Google cloud console.

kubectl get nodes


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

Wordpress web application can be deployed on Kubernetes using below command.

kubectl create deployment devwebserver --image=wordpress
No alt text provided for this image

Load balancer can be enabled for the web application as below.

kubectl expose deploy devwebserver --type=LoadBalancer --port=80


No alt text provided for this image

Load balancer IP can be identified using below command.

kubectl get services
No alt text provided for this image

The web application can be configured with Production database as per steps below.

No alt text provided for this image


No alt text provided for this image


No alt text provided for this image


No alt text provided for this image


No alt text provided for this image

Now, web application is ready to be accessed through the load balancer URL.

No alt text provided for this image

Application data store can be verified on the database.

No alt text provided for this image



To view or add a comment, sign in

Others also viewed

Explore content categories