Project Deployment on Google Cloud Platform using Kubernetes
Task Details:
- Create multiple projects for Development and Production
- Create VPC network for both the projects
- Create a link between both the VPC networks using VPC Peering
- Create a Kubernetes Cluster in Development project and launch any web application with the Load balancer
- Create an SQL server in the production project and create a database
- 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.
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
For using gcloud CLI, to configure Kubernetes on GCP, Beta Commands add-on needs to be installed.
3. Enabling billing for the projects
Billing needs to be enabled for using GCP services for both the projects.
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
Defining Custom subnet IP range:
gcloud compute networks create dev --project=npdevenv --description=DevelopmentVPCNetwork --subnet-mode=custom --bgp-routing-mode=regional
Production:
Creating Network:
gcloud compute networks create prod --project=npprodenv --description=ProductionVPCNetwork --subnet-mode=custom --bgp-routing-mode=regional
Defining Custom Subnet IP range:
gcloud compute networks subnets create subnetprodvpc --project=npprodenv --range=110.0.20.0/24 --network=prod --region=us-central1
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
Production:
gcloud compute --project=npprodenv firewall-rules create prodfirewall --description=ProdFirewall --direction=INGRESS --network=prod --action=ALLOW --rules=tcp:22,icmp
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
gcloud compute --project=npdevenv networks peerings create devprodvpcnetpeering --network=dev --peer-network=prod --peer-project=npprodenv
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
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
Once Kubernetes clusters are setup, distributed compute can be verified.
For controlling Kubernetes clusters using CLI, below command should be executed.
gcloud container clusters get-credentials kubernetescluster --project npdevenv --region asia-northeast
Nodes created can be verified using below command and on Google cloud console.
kubectl get nodes
Wordpress web application can be deployed on Kubernetes using below command.
kubectl create deployment devwebserver --image=wordpress
Load balancer can be enabled for the web application as below.
kubectl expose deploy devwebserver --type=LoadBalancer --port=80
Load balancer IP can be identified using below command.
kubectl get services
The web application can be configured with Production database as per steps below.
Now, web application is ready to be accessed through the load balancer URL.
Application data store can be verified on the database.
Nicely explained