Set up and Configure a Cloud Environment in Google Cloud: Challenge Lab
In this article, we will go through the lab to Set up and Configure a Cloud Environment in Google Cloud. In the previous, lab you will get familiar with Google Cloud IAM, Introduction to SQL for BigQuery and Cloud SQL, Multiple VPC Networks, Cloud Monitoring, Deployment Manager, and Managing Deployments Using Kubernetes Engine.
The challenge contains 9 required tasks
- Create development VPC manually
- Create production VPC using Deployment Manager
- Create bastion host
- Create and configure Cloud SQL Instance
- Create Kubernetes cluster
- Prepare the Kubernetes cluster
- Create a WordPress deployment
- Enable monitoring
- Provide access for an additional engineer
Some Jooli Inc. standards you should follow:
- Create all resources in the
us-east1
region andus-east1-b
zone, unless otherwise directed. - Use the project VPCs.
- Naming is normally team-resource, e.g. an instance could be named kraken-webserver1.
- Allocate cost-effective resource sizes. Projects are monitored and excessive resource use will result in the containing project’s termination (and possibly yours), so beware. This is the guidance the monitoring team is willing to share: unless directed, use
n1-standard-1
.
1.Create development VPC manually
The First step is to create a VPC called griffin-dev-vpc
- In the GCP Console go to Navigation Menu >VPC Network
- Click on the Create VPC network.
- In the Name, field write
griffin-dev-vpc
. - Select Custom for the Subnet creation mode.
- Configure the following settings in Subnet creation:
Field- Value
Name:- griffin-dev-wp
Region:- us-east1
IP address range:- 192.168.16.0/20
- Click Add subnet and add
griffin-dev-mgmt
subnet. - Configure the following settings in Subnet creation:
Name:- griffin-dev-mgmt
Region:- us-east1
IP address range:- 192.168.16.0/20
- Click on Create.
2.Create production VPC using Deployment Manager
This step is to Create production VPC using Deployment Manager
- Activate the cloud shell and type the following command.
gsutil cp -r gs://cloud-training/gsp321/dm ~/
- Now we have to edit
prod-network.yaml
configuration file.
cd dm
edit prod-network.yaml
- Replace SET_REGION to
us-east1-b
zone in the editor, and save the changes.
- Now you have to create the production VPC network with the configuration files:
gcloud deployment-manager deployments create griffin-prod --config prod-network.yaml
3.Create bastion host
This step is to create a bastion host.
- In the GCP Console go to Navigation Menu >Compute Engine > VM Instance> Create.
- Configure the following settings to create the bastion host.
Field- Value
Name:- griffin-dev-db
Region:- us-east1
- Expand the Management, security section.
- Now Add bastion to the Network tags field.
- Click Create.
- Click Add network interface, make sure that you set up two network interfaces,
griffin-dev-mgmt
griffin-prod-mgmt
Now we have to create two VPC Networks
allow-bastion-dev-ssh
- In the GCP Console go to Navigation Menu >VPC Network > Firewall.
- Click Create firewall rule.
- Configure the following settings:
Name:-allow-bastion-dev-ssh
Network:-griffin-dev-vpc
Targets:-bastion
Source IP ranges:-192.168.32.0/20
Protocols and ports:- tcp: 22
- Click Create.
VPC Network for allow-bastion-prod-ssh
- In the GCP Console go to Navigation Menu >VPC Network > Firewall.
- Click Create firewall rule.
- Configure the following settings:
Name:-allow-bastion-prod-ssh
Network:-griffin-dev-vpc
Targets:-bastion
Source IP ranges:-192.168.32.0/20
Protocols and ports:- tcp: 22
- Click Create.
4.Create and configure Cloud SQL Instance
This step is to create and configure Cloud SQL Instance.
- In the GCP Console go to Navigation Menu >SQL.
- Click Create Instance>Choose MySQL.
- Use the following parameters to create the instance:
Field- Value
Name:- griffin-dev-db
Region:- us-east1
Zone:- us-east1-b
Root password:- e.g. Mayank@1234
- Click Create.
- Click on the
griffin-dev-db
- Under Connect to this instance, click on Connect using Cloud Shell.
- Run the commands in Cloud Shell:
gcloud sql connect griffin-dev-db --user=root --quiet
- Enter the Root password written in the previous step.
- In the SQL console, run the following query to create the WordPress database:
CREATE DATABASE wordpress;
GRANT ALL PRIVILEGES ON wordpress.* TO "wp_user"@"%" IDENTIFIED BY "stormwind_rules";
FLUSH PRIVILEGES;
- Enter
exit
to exit from SQL.
5.Create Kubernetes cluster
This step is to create a Kubernetes cluster.
- In the GCP Console go to Navigation Menu > Kubernetes Engine > Clusters.
- Click Create cluster.
- In the Cluster basics tab, configure:
Name: griffin-dev
Zone: us-east1-b
- Click default-pool under NODE POOLS and set Number of nodes:
2
- Click Nodes Under default-pool, and set Machine type:
n1-standard-4
- Go to the Network tab, set
Network: griffin-dev-vpc
Node subnet: griffin-dev-wp
- Click Create.
6.Prepare the Kubernetes cluster
This step is to Edit the YAML file.
- In the Cloud Shell, use the following command to copy the files for the Kubernetes:
gsutil cp -r gs://cloud-training/gsp321/wp-k8s ~/
- Edit the YAML file
cd ~/wp-k8s
edit wp-env.yaml
- Replace
username_goes_here
andpassword_goes_here
towp_user
andstormwind_rules.
- Save the changes.
- Connect the Kubernetes cluster
gcloud container clusters get-credentials griffin-dev --zone=us-east1
- Deploy the configuration to the cluster using.
kubectl apply -f wp-env.yaml
- Create the key, and then add the key to the Kubernetes environment:
gcloud iam service-accounts keys create key.json \
--iam-account=cloud-sql-proxy@$GOOGLE_CLOUD_PROJECT.iam.gserviceaccount.com
kubectl create secret generic cloudsql-instance-credentials \
--from-file key.json
7.Create a WordPress deployment
This step is to Create a WordPress deployment.
- In the Cloud, Shell open the WordPress deployment YAML file.
cd ~/wp-k8s
edit wp-deployment.yaml
- Replace
YOUR_SQL_INSTANCE
withgriffin-dev-db
’s Instance connection name.
- Save the file.
- Now run Deployment and service file in Cloud Shell.
kubectl create -f wp-deployment.yaml
kubectl create -f wp-service.yaml
8.Enable monitoring
This step is to Enable monitoring.
- In the GCP Console go to Navigation Menu > Monitoring.
- Click Uptime checks.
- Configure using the following parameters:
Field- Value
Title -WordPress Uptime
Check Type -HTTP
Resource Type -URL
Hostname- YOUR-WORDPRESS_ENDPOINT
Path- /
- Click on Test and Save after that.
9: Provide access for an additional engineer
This step is to Provide access for Second User.
- In the GCP Console go to Navigation Menu > IAM & Admin > IAM.
- Click +ADD.
- Copy and paste the second user account for the lab to the New members field.
- In the Role dropdown, select Project > Editor.
- Click Save.
Congratulations! Done with the challenge lab.
Stay tuned till the next blog
If you Want to Connect with Me:
Linkedin: https://www.linkedin.com/in/mayank-chourasia-38421a134/
Twitter: https://twitter.com/ChourasiaMayank.
Google Cloud Google Developers Google News Lab Kubernetes Advocate Qwiklabs