Launching WebApp Using GKE and SQL services of GCP
Chirag Deepak Ratvekar
Mainframe Developer at Wipro | Microsoft Certified Azure Administrator Associate | Cloud & Data Enthusiast.
project of launching webapp on cloud,
project details...
1. Multiple projects namely developer and production.
2. VPC network for both the projects.
3. Link between both the VPC networks using VPC Peering.
4. Kubernetes Cluster in developer project and launching WordPress with the Load balancer.
5 SQL server in the production project and create a database.
6. Connect the SQL database to the web application launched in the Kubernetes cluster.
---------------------------------------------------------------------------------------------------------------
Let's start the practical part.
1) You must have the GCP account or GCP IAM account.
2) Create a Development project and the Production project as shown.
3 . Now create the VPC in both projects in different region as you want, we have created as.
-In Production Project VPC is created in the asia-southeast1(Singapore) with 1 subnet.
-In Development Project VPC is created in the us-east1 (USA) with 1 subnet.
NOTE: You can create VPC in any region as you want with as many subnet, here we were created the 1 subnet for each vpc as we required only 1.
process for another vpc.
4) Then we have to connect the both VPC internally, as private ip can only connect to private if they are in same network or connected with LAN so here we are connecting with LAN refer this for more, here we are not making SQL database public that's why we need to make internal connection of the both VPC, so that all the instances in both VPC can interact with each other using private ip, but here we are allowing all ip to connect to sql instance either publicly or privately. Peering should be from both side means we have to do connection/peering from both VPC as shown.
5) Create database from SQL service as shown.
After creation you will see this dashboard as above.
Here you can create Database and user also as shown, but here we are going to use root user and as we are installing the WordPress so we don't need to create database WordPress will create database automatically, though we have shown how to create database and user.
Also you can create the database and user from the cli, cloud shell or from your CMD if you knows the quries of SQl, we have shown below how to connect with sql instance using cloud shell.
6) Now we have to create the Kubernetes cluster using GKE(Google Kubernetes Engine) as shown. In the Gcp kubernetes is the fully managed service by the GCP.
In cluster basics you can select any region as you want, hare we have selected us-east1 because our VPC from project with name development is in same region and we have selected 3 subnets so our instance will launch in three subnets and also selects the version of the master node of the K8S's master-slave cluster.
Next is Node pool details here we have to mention the information about the slave node of the K8S's master-slave cluster like name of cluster, which version you want, no of node per Zone, zone means subnet, if you knows scaling then you can mention the minimum and the maximum number of instance or pod.
Commands to run for deployment :
//To connect to master slave from url #gcloud container clusters ger-credentials k8s-for-wordpress --region us-east1 --project sswprod417752 //To get pods #kubectl get pods //To get Nodes #kubectl get nodes //To get services #kubectl get service //To deploy the instance #kunectl create deployment ssw-wp --image=wprdpress //To expose the deployment or to attache a load balancer to master node #kunectl expose deployment ssw-wp --type=LoadBalancer --port=80 //To get services also you will get the ip of loadbalancer
#kubectl get service
And finally the WordPress is launched. So here is the complete environment for the webapp.
Software Engineer At BUSINESSNEXT
4 年Nice job