GCP - Commands

 

gcloud compute zones list | grep
gcloud compute zones list | grep us-central1
gcloud config set compute/zone us-central1-b

# Create a VM:
gcloud compute instances create "my-vm-2" \
--machine-type "n1-standard-1" \
--image-project "debian-cloud" \
--image "debian-9-stretch-v20170918" \
--subnet "default"

# Install nginx server
sudo apt-get install nginx-light -y

# vi index file.
sudo vi /var/www/html/index.nginx-debian.html


>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
gcloud config set project

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Lab:
bloghost: 10.128.0.2 35.232.13.96

export LOCATION=US

# In Cloud Shell, the DEVSHELL_PROJECT_ID environment variable contains your project ID. Enter this command to make a bucket named after your project ID:
gsutil mb -l $LOCATION gs://$DEVSHELL_PROJECT_ID

# Retrieve a banner image from a publicly accessible Cloud Storage location:
gsutil cp gs://cloud-training/gcpfci/my-excellent-blog.png \
my-excellent-blog.png

# Copy the banner image to your newly created Cloud Storage bucket:
gsutil cp my-excellent-blog.png \
gs://$DEVSHELL_PROJECT_ID/my-excellent-blog.png


SQL Server: blog-db
SQL Root Password: blog-db123

SQL Instance IP: 35.192.66.55
qwiklabs-gcp-11dbfcfe711df298:us-central1:blog-db

blogdbuser
blogdbuser123


<html>
<head><title>Welcome to my excellent blog</title></head>
<body>
<h1>Welcome to my excellent blog</h1>
<?php
$dbserver = "CLOUDSQLIP";
$dbuser = "blogdbuser";
$dbpassword = "DBPASSWORD";
// In a production blog, we would not store the MySQL
// password in the document root. Instead, we would store it in a
// configuration file elsewhere on the web server VM instance.

$conn = new mysqli($dbserver, $dbuser, $dbpassword);

if (mysqli_connect_error()) {
echo ("Database connection failed: " . mysqli_connect_error());
} else {
echo ("Database connection succeeded.");
}
?>
</body></html>

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Lab 05: Kubernetes

export MY_ZONE=us-central1-a

# Start a Kubernetes cluster managed by Kubernetes Engine. Name the cluster webfrontend and configure it to run 2 nodes:

gcloud container clusters create webfrontend --zone $MY_ZONE --num-nodes 2


WARNING: Currently node auto repairs are disabled by default. In the future this will change and they will be enabled by default. Use `--[no-]enable-
autorepair` flag to suppress this warning.
WARNING: Currently VPC-native is not the default mode during cluster creation. In the future, this will become the default mode and can be disabled u
sing `--no-enable-ip-alias` flag. Use `--[no-]enable-ip-alias` flag to suppress this warning.
WARNING: Starting in Kubernetes v1.10, new clusters will no longer get compute-rw and storage-ro scopes added to what is specified in --scopes (thoug
h the latter will remain included in the default --scopes). To use these scopes, add them explicitly to --scopes. To use the new behavior, set contai
ner/new_scopes_behavior property (gcloud config set container/new_scopes_behavior true).

Created [https://container.googleapis.com/v1/projects/qwiklabs-gcp-9933adac926cc243/zones/us-central1-a/clusters/webfrontend].
To inspect the contents of your cluster, go to: https://console.cloud.google.com/kubernetes/workload_/gcloud/us-central1-a/webfrontend?project=qwiklabs-gcp-9933adac926cc243
kubeconfig entry generated for webfrontend.
NAME LOCATION MASTER_VERSION MASTER_IP MACHINE_TYPE NODE_VERSION NUM_NODES STATUS
webfrontend us-central1-a 1.9.7-gke.3 35.224.83.156 n1-standard-1 1.9.7-gke.3 2 RUNNING

kubectl version

kubectl run nginx --image=nginx:1.10.0

kubectl get pods

kubectl expose deployment nginx --port 80 --type LoadBalancer

google700255_student@qwiklabs-gcp-9933adac926cc243:~$ kubectl get services
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.51.240.1 <none> 443/TCP 11m
nginx LoadBalancer 10.51.245.247 104.197.35.213 80:32154/TCP 2m

kubectl scale deployment nginx --replicas 2
kubectl scale deployment nginx --replicas 3

 

gcloud container clusters get-credentials webfrontend --zone us-central1-a --project qwiklabs-gcp-9933adac926cc243

 

 



GCP APP ENGINE:
From GCP shell:

$ git clone https://github.com/GoogleCloudPlatform/appengine-guestbook-python
$ cd appengine-guestbook-python
$ ls -l
$ cat app.yaml
$ dev_appserver.py ./app.yaml

Deploy the application to App Engine using this command:
$ gcloud app deploy ./index.yaml ./app.yaml

You can stream logs from the command line by running:
$ gcloud app logs tail -s default

To view your application in the web browser run:
$ gcloud app browse

 

Add comment


Security code
Refresh

Category: