DEPLOYING WORDPRESS ON THE TOP OF KUBERNETE CLUSTER FURTHER CONNECTING IT WITH SQL DATABASE USING GOOGLE CLOUD PLATFORM
Google Cloud Platform, offered by Google, is cloud computing services that run on the same infrastructure that Google uses internally such as Gmail, YouTube.
🔶First, we will create multiple projects.
🔶Inside both the projects, we will create a VPC network.
🔶After creating both the projects we will do VPC Peering.
🔶Then in one of the projects, we will launch the Kubernetes cluster.
🔶And in the other project, we will launch an SQL server.
🔶Then in the project in which we have launched the Kubernetes cluster, we will launch WordPress on the top of it.
So, Lets Get started with our task :
◼️ CREATION OF PROJECTS:
We will start by creating two projects named development and production. When we log in to our GCP account by default there is one project present. So, to create any new project we just have to go to a new project and then we can create.
Now we have two projects.
So, we will create a VPC network inside both the projects.
◼️ VPC CREATION:
To create a VPC network we have to service called VPC Network, inside that we have the option to create a new VPC network.
Inside that, we just have to provide our network name, subnet name, IP address range, and region and then just click on the create button and we have our VPC network ready.
Also, we will allow all to connect to our VPC for this we will also create a FireWall rule where we will set IP range
This will allow all the resources to connect to our VPC.
Using the same steps we have to create the network inside the other project also.
◼️ NETWORK PEERING:
Then we have a service called VPC network peering, inside that as we want to connect with other projects so we should click on the option ‘In other project’ and then just provide project-id and network name.
◼️ SETUP OF KUBERNETES CLUSTER:
Now, we will create a Kubernetes cluster. So, we will go inside the Kubernetes engine and then select clusters.
Then we have to click on create cluster, inside that we have to provide cluster-name, location-type, and zone.
So inside location-type we have two options regional, zonal. Regional cluster creates three cluster masters across three zones and, by default, create nodes in three zones, or as many zones as desired. zonal clusters have a single control plane in a single zone.
By default, the no of nodes is 3. If we want we can change it.
We can also access GCP using our command line but to do so there should be gcloud installed on our computer.
If you want to become the client of the Kubernetes cluster you need kubectl command. so, you have to install it.
◼️ SETTING UP DATABASE:
So, we are ready with our Kubernetes cluster now we will launch the SQL server in other project.
We have to click on create instance then we have to choose our database engine. After choosing it will ask instance id, password, region, zone, database version.
Now, click on Show Configuration Options so that we can make connection rules that will help to connect the DataBase.
Just put the name of the connection and IP range that you want to connect from and to.
Here, we will be allowing all to connect to our DataBase through the DataBase IP.
NOTE — This is not good for security purposes because in DataBase we have lots of Crucial Data.
We are just practicing it therefore we will be allowing all to connect to our DataBase.
After that, we just have to click on create and our SQL server is also ready. After that, we can also create our database.
Now we will launch our WordPress on top of the cluster.
To do this we have to connect our cluster.
For connecting just click on the connect button and copy the command and just paste it in your command line or gcloud shell.
Make sure you have pre-installed gcloud SDK and KUBECTL which will help us to interact with the cluster.
Now we will be launching WordPress for this
We will run the command
kubectl create deployment deployment_name --image=wordpress
This will create a deployment and will launch WordPress. Now we will expose our created deployment and will attach LoadBalancer with it so that we can divide the traffic between nodes.
For this, Just run the command
kubectl expose deployment deployment_name --type=LoadBalancer --port=80
Now, Let’s check whether everything is right or not.
kubectl get all
JUST COPY THE IP OF LOADBALANCER.
This command will show all the resources that had been deployed.
Just copy the IP address and paste it in the browser for connecting to WordPress.
It’s Done!! Famous Five Minute WordPress Installation has been launched.
Now we will connect our SQL DataBase with WordPress Application.
It will ask database name, username, password, Database host.
After, proving all the information it’s done. Now our WordPress is connected to the SQL server.
YES!! Its finally done we have completed all the steps. Now, just fill the SITE DETAILS and you are good to go.
Hope this will help.