Advertisement
ctrlvfailed

gcp3

Jun 19th, 2020
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.43 KB | None | 0 0
  1.  
  2. arrow_back
  3. Console and Cloud Shell
  4. Toggle Lab Panel
  5. avatar image
  6. Console and Cloud Shell
  7. 40 minutes Free
  8. Rate Lab
  9. Overview
  10.  
  11. In this lab, you become familiar with the Google Cloud web-based interface. There are two integrated environments: a GUI (graphical user interface) environment called the Cloud Console, and a CLI (command-line interface) called Cloud Shell. In this class you use both environments.
  12.  
  13. Here are a few things you need to know about the Cloud Console:
  14.  
  15. The Cloud Console is under continuous development, so occasionally the graphical layout changes. This is most often to accommodate new Google Cloud features or changes in the technology, resulting in a slightly different workflow.
  16.  
  17. You can perform most common Google Cloud actions in the Cloud Console, but not all actions. In particular, very new technologies or sometimes detailed API or command options are not implemented (or not yet implemented) in the Cloud Console. In these cases, the command line or the API is the best alternative.
  18.  
  19. The Cloud Console is extremely fast for some activities. The Cloud Console can perform multiple actions on your behalf that might require many CLI commands. It can also perform repetitive actions. In a few clicks you can accomplish activities that would require a great deal of typing and would be prone to typing errors.
  20.  
  21. The Cloud Console is able to reduce errors by only offering up through its menus valid options. It is able to leverage access to the platform "behind the scenes" through the SDK to validate configuration before submitting changes. A command line can't do this kind of dynamic validation.
  22.  
  23. Objectives
  24.  
  25. In this lab, you learn how to perform the following tasks:
  26.  
  27. Get access to Google Cloud.
  28.  
  29. Create a Cloud Storage bucket using the Cloud Console.
  30.  
  31. Create a Cloud Storage bucket using Cloud Shell.
  32.  
  33. Become familiar with Cloud Shell features.
  34.  
  35. Qwiklabs setup
  36.  
  37. For each lab, you get a new GCP project and set of resources for a fixed time at no cost.
  38.  
  39. Make sure you signed into Qwiklabs using an incognito window.
  40.  
  41. Note the lab's access time (for example, img/time.png and make sure you can finish in that time block.
  42.  
  43. There is no pause feature. You can restart if needed, but you have to start at the beginning.
  44.  
  45. When ready, click img/start_lab.png.
  46.  
  47. Note your lab credentials. You will use them to sign in to Cloud Platform Console. img/open_google_console.png
  48.  
  49. Click Open Google Console.
  50.  
  51. Click Use another account and copy/paste credentials for this lab into the prompts.
  52.  
  53. If you use other credentials, you'll get errors or incur charges.
  54.  
  55. Accept the terms and skip the recovery resource page.
  56.  
  57. Do not click End Lab unless you are finished with the lab or want to restart it. This clears your work and removes the project.
  58. Task 1: Create a bucket using the Cloud Console
  59.  
  60. In this task, you create a bucket. However, the text also helps you become familiar with how actions are presented in the lab instructions in this class and teaches you about the Cloud Console interface.
  61. Navigate to the Storage service and create the bucket
  62.  
  63. In the Cloud Console, on the Navigation menu (9a951fa6d60a98a5.png), click Storage > Browser.
  64.  
  65. Click Create bucket.
  66.  
  67. For Name, type a globally unique bucket name, and leave all other values as their defaults.
  68.  
  69. Click Create.
  70.  
  71. Explore features in the Cloud Console
  72.  
  73. The Google Cloud menu contains a Notifications (e921662595351d9e.png) icon. Sometimes, feedback from the underlying commands is provided there. If you are not sure what is happening, check Notifications for additional information and history.
  74.  
  75. Click Check my progress to verify the objective.
  76. Create a bucket using the Cloud Console
  77. Task 2: Access Cloud Shell
  78.  
  79. In this section, you explore Cloud Shell and some of its features.
  80.  
  81. You can use the Cloud Shell to manage projects and resources via command line, without having to install the Cloud SDK and other tools on your computer.
  82.  
  83. Cloud shell provides the following:
  84.  
  85. Temporary Compute Engine VM
  86. Command-line access to the instance via a browser
  87. 5 GB of persistent disk storage ($HOME dir)
  88. Pre-installed Cloud SDK and other tools
  89. gcloud: for working with Google Compute Engine and many Google Cloud services
  90. gsutil: for working with Cloud Storage
  91. kubectl: for working with Google Container Engine and Kubernetes
  92. bq: for working with BigQuery
  93. Language support for Java, Go, Python, Node.js, PHP, and Ruby
  94. Web preview functionality
  95. Built-in authorization for access to resources and instances
  96.  
  97. After 1 hour of inactivity, the Cloud Shell instance is recycled. Only the /home directory persists. Any changes made to the system configuration, including environment variables, are lost between sessions.
  98. Open Cloud Shell and explore features
  99.  
  100. In the Google Cloud menu, click Activate Cloud Shell (e92fcd01cbb5e0ff.png). If prompted, click Continue. Cloud Shell opens at the bottom of the Cloud Console window.
  101.  
  102. There are three icons to the far right of the Cloud Shell toolbar:
  103.  
  104. Hide/Restore: The first one hides and restores the window, giving you full access to the Cloud Console without closing Cloud Shell.
  105.  
  106. Open in new window: Having Cloud Shell at the bottom of the Cloud Console is useful when you are issuing individual commands. However, sometimes you will be editing files or want to see the full output of a command. For these uses, this icon pops the Cloud Shell out into a full-sized terminal window.
  107.  
  108. Close all tabs: This icon closes Cloud Shell. Every time you close Cloud Shell, the virtual machine is recycled and all machine context is lost.
  109.  
  110. Close Cloud Shell now.
  111.  
  112. Task 3: Create a bucket using Cloud Shell
  113. Create a second bucket and verify in the Cloud Console
  114.  
  115. Open Cloud Shell again.
  116.  
  117. Use the gsutil command to create another bucket. Replace <BUCKET_NAME> with a globally unique name (you can append a 2 to the globally unique bucket name you used previously):
  118.  
  119. gsutil mb gs://<BUCKET_NAME>
  120.  
  121. In the Cloud Console, on the Navigation menu (9a951fa6d60a98a5.png), click Storage > Browser, or click Refresh if you are already in the Storage Browser. The second bucket should be displayed in the Buckets list.
  122.  
  123. You have performed equivalent actions using the Cloud Console and Cloud Shell.
  124.  
  125. You created a bucket using the Cloud Console and another bucket using Cloud Shell.
  126.  
  127. Click Check my progress to verify the objective.
  128. Create a bucket using Cloud Shell
  129. Task 4: Explore more Cloud Shell features
  130. Upload a file
  131.  
  132. Open Cloud Shell.
  133.  
  134. Click the three dots (b4af82f98f85f64f.png) icon in the Cloud Shell toolbar to display further options.
  135.  
  136. Click Upload file. Upload any file from your local machine to the Cloud Shell VM. This file will be referred to as [MY_FILE].
  137.  
  138. In Cloud Shell, type ls to confirm that the file was uploaded.
  139.  
  140. Copy the file into one of the buckets you created earlier in the lab. Replace [MY_FILE] with the file you uploaded and [BUCKET_NAME] with one of your bucket names:
  141.  
  142. gsutil cp [MY_FILE] gs://[BUCKET_NAME]
  143.  
  144. If your filename has whitespaces, ensure to place single quotes around the filename. For example, gsutil cp ‘my file.txt' gs://[BUCKET_NAME]
  145.  
  146. You have uploaded a file to the Cloud Shell VM and copied it to a bucket.
  147.  
  148. Explore the options available in Cloud Shell by clicking on different icons in the Cloud Shell toolbar.
  149. Close all the Cloud Shell sessions.
  150.  
  151. Click Check my progress to verify the objective.
  152. Upload a file to Storage bucket
  153. Task 5: Create a persistent state in Cloud Shell
  154.  
  155. In this section you will learn a best practice for using Cloud Shell. The gcloud command often requires specifying values such as a Region or Zone or Project ID. Entering them repeatedly increases the chances of making typing errors. If you use Cloud Shell a lot, you may want to set common values in environment variables and use them instead of typing the actual values.
  156. Identify available regions
  157.  
  158. Open Cloud Shell from the Cloud Console. Note that this allocates a new VM for you.
  159.  
  160. To list available regions, execute the following command:
  161.  
  162. gcloud compute regions list
  163.  
  164. Select a region from the list and note the value in any text editor. This region will now be referred to as [YOUR_REGION] in the remainder of the lab.
  165.  
  166. Create and verify an environment variable
  167.  
  168. Create an environment variable and replace [YOUR_REGION] with the region you selected in the previous step:
  169.  
  170. INFRACLASS_REGION=[YOUR_REGION]
  171.  
  172. Verify it with echo:
  173.  
  174. echo $INFRACLASS_REGION
  175.  
  176. You can use environment variables like this in gcloud commands to reduce the opportunities for typos, and so that you won't have to remember a lot of detailed information.
  177.  
  178. Every time you close Cloud Shell and reopen it, a new VM is allocated, and the environment variable you just set disappears. In the next steps, you create a file to set the value so that you won't have to enter the command each time Cloud Shell is cycled.
  179. Append the environment variable to a file
  180.  
  181. Create a subdirectory for materials used in this class:
  182.  
  183. mkdir infraclass
  184.  
  185. Create a file called config in the infraclass directory:
  186.  
  187. touch infraclass/config
  188.  
  189. Append the value of your Region environment variable to the config file:
  190.  
  191. echo INFRACLASS_REGION=$INFRACLASS_REGION >> ~/infraclass/config
  192.  
  193. Create a second environment variable for your Project ID, replacing [YOUR_PROJECT_ID] with your Project ID. You can find the project ID on the Cloud Console Home page.
  194.  
  195. INFRACLASS_PROJECT_ID=[YOUR_PROJECT_ID]
  196.  
  197. Append the value of your Project ID environment variable to the config file:
  198.  
  199. echo INFRACLASS_PROJECT_ID=$INFRACLASS_PROJECT_ID >> ~/infraclass/config
  200.  
  201. Use the source command to set the environment variables, and use the echo command to verify that the project variable was set:
  202.  
  203. source infraclass/config
  204. echo $INFRACLASS_PROJECT_ID
  205.  
  206. This gives you a method to create environment variables and to easily recreate them if the Cloud Shell is cycled. However, you will still need to remember to issue the source command each time Cloud Shell is opened.
  207.  
  208. In the next step you will modify the .profile file so that the source command is issued automatically any time a terminal to Cloud Shell is opened.
  209.  
  210. Close and re-open Cloud Shell. Then issue the echo command again:
  211.  
  212. echo $INFRACLASS_PROJECT_ID
  213.  
  214. There will be no output because the environment variable no longer exists.
  215. Modify the bash profile and create persistence
  216.  
  217. Edit the shell profile with the following command:
  218.  
  219. nano .profile
  220.  
  221. Add the following line to the end of the file:
  222.  
  223. source infraclass/config
  224.  
  225. Press Ctrl+O, ENTER to save the file, and then press Ctrl+X to exit nano.
  226.  
  227. Close and then re-open Cloud Shell to cycle the VM.
  228.  
  229. Use the echo command to verify that the variable is still set:
  230.  
  231. echo $INFRACLASS_PROJECT_ID
  232.  
  233. You should now see the expected value that you set in the config file.
  234.  
  235. If you ever find your Cloud Shell environment corrupted, you can find instructions on resetting it here:
  236.  
  237. Resetting Cloud Shell
  238.  
  239. This will cause everything in your Cloud Shell environment to be set back to its original default state.
  240.  
  241. Task 6: Review the Google Cloud interface
  242.  
  243. Cloud Shell is an excellent interactive environment for exploring Google Cloud using Google Cloud SDK commands like gcloud and gsutil.
  244.  
  245. You can install the Google Cloud SDK on a computer or on a VM instance in Google Cloud. The gcloud and gsutil commands can be automated using a scripting language like bash (Linux) or Powershell (Windows). You can also explore using the command-line tools in Cloud Shell, and then use the parameters as a guide for re-implementing in the SDK using one of the supported languages.
  246.  
  247. The Google Cloud interface consists of two parts: the Cloud Console and Cloud Shell.
  248.  
  249. The Console:
  250.  
  251. Provides a fast way to get things done
  252. Presents options to you, instead of requiring you to know them
  253. Performs behind-the-scenes validation before submitting the commands
  254.  
  255. Cloud Shell provides:
  256.  
  257. Detailed control
  258. Complete range of options and features
  259. A path to automation through scripting
  260.  
  261. End your lab
  262.  
  263. When you have completed your lab, click End Lab. Qwiklabs removes the resources you’ve used and cleans the account for you.
  264.  
  265. You will be given an opportunity to rate the lab experience. Select the applicable number of stars, type a comment, and then click Submit.
  266.  
  267. The number of stars indicates the following:
  268.  
  269. 1 star = Very dissatisfied
  270. 2 stars = Dissatisfied
  271. 3 stars = Neutral
  272. 4 stars = Satisfied
  273. 5 stars = Very satisfied
  274.  
  275. You can close the dialog box if you don't want to provide feedback.
  276.  
  277. For feedback, suggestions, or corrections, please use the Support tab.
  278.  
  279. Copyright 2019 Google LLC All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.
  280. Overview
  281. Objectives
  282. Task 1: Create a bucket using the Cloud Console
  283. Task 2: Access Cloud Shell
  284. Task 3: Create a bucket using Cloud Shell
  285. Task 4: Explore more Cloud Shell features
  286. Task 5: Create a persistent state in Cloud Shell
  287. Task 6: Review the Google Cloud interface
  288. End your lab
  289. Score
  290. 15/15
  291.  
  292. Create a bucket using the GCP Console
  293.  
  294. Run Step
  295.  
  296. 5 / 5
  297.  
  298. Create a bucket using Cloud Shell
  299.  
  300. Run Step
  301.  
  302. 5 / 5
  303.  
  304. Upload a file to Storage bucket
  305.  
  306. Run Step
  307.  
  308. 5 / 5
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement