
Before you begin
- Labs create a Google Cloud project and resources for a fixed time
- Labs have a time limit and no pause feature. If you end the lab, you'll have to restart from the beginning.
- On the top left of your screen, click Start lab to begin
Create and run a Job
/ 50
Create and run a CronJob
/ 50
In this lab, you define and run Jobs and CronJobs.
In GKE, a Job is a controller object that represents a finite task. Jobs manage a task as it runs to completion, rather than managing an ongoing desired state such as maintaining the total number of running Pods.
CronJobs perform finite, time-related tasks that run once or repeatedly at a time that you specify using Job objects to complete their tasks.
In this lab, you learn how to perform the following tasks:
For each lab, you get a new Google Cloud project and set of resources for a fixed time at no cost.
Sign in to Qwiklabs using an incognito window.
Note the lab's access time (for example, 1:15:00
), and make sure you can finish within that time.
There is no pause feature. You can restart if needed, but you have to start at the beginning.
When ready, click Start lab.
Note your lab credentials (Username and Password). You will use them to sign in to the Google Cloud Console.
Click Open Google Console.
Click Use another account and copy/paste credentials for this lab into the prompts.
If you use other credentials, you'll receive errors or incur charges.
Accept the terms and skip the recovery resource page.
After you complete the initial sign-in steps, the project dashboard appears.
Google Cloud Shell is a virtual machine that is loaded with development tools. It offers a persistent 5GB home directory and runs on the Google Cloud.
Google Cloud Shell provides command-line access to your Google Cloud resources.
In Cloud console, on the top right toolbar, click the Open Cloud Shell button.
Click Continue.
It takes a few moments to provision and connect to the environment. When you are connected, you are already authenticated, and the project is set to your PROJECT_ID. For example:
gcloud is the command-line tool for Google Cloud. It comes pre-installed on Cloud Shell and supports tab-completion.
Output:
Example output:
Output:
Example output:
In GKE, a Job is a controller object that represents a finite task.
In this task, you create a Job, inspect its status, and then remove it.
Let's create a sample Job that computes the value of Pi to 2,000 places and then prints the result.
example-job.yaml
with nano using the following command:example-job.yaml
file:Press Ctrl+O, and then press Enter to save your edited file.
Press Ctrl+X to exit the nano text editor.
To create a Job from this file, execute the following command:
Click Check my progress to verify the objective.
You will see details of the job, including the Pod statuses indicating how many jobs are still running, how many completed successfully and how many failed:
Your Pod name might be different from the example output:
Make a note of one of the Pod names.
When a Job completes, the Job stops creating Pods. The Job API object is not removed when it completes, which allows you to view its status. Pods created by the Job are not deleted, but they are terminated. Retention of the Pods allows you to view their logs and interact with them.
The output should look like the example:
The output will show that the job wrote the first two thousand digits of pi to the Pod log.
If you try to query the logs again the command will fail as the Pod can no longer be found.
You can create CronJobs to perform finite, time-related tasks that run once or repeatedly at a time that you specify.
In this task, you create and run a CronJob, and then you clean up and delete the Job.
This CronJob deploys a new container every minute that prints the time, date and "Hello, World!".
example-cronjob.yaml
with nano using the following command:example-cronjob.yaml
file:Press Ctrl+O, and then press Enter to save your edited file.
Press Ctrl+X to exit the nano text editor.
schedule
field, which accepts a time in the Unix standard crontab
format.
All CronJob times are in UTC:
schedule
field also accepts * and ? as wildcard values. Combining / with ranges specifies that the task should repeat at a regular interval. In the example, */1 * * * *
indicates that the task should repeat every minute of every day of every month.
Click Check my progress to verify the objective.
The output should look like the example:
[job_name]
is the name of your job:You will see details of the job, including the Pod statuses showing that one instance of this job was run:
This will display the output of the shell script configured in the CronJob:
Your job names might be different from the example output. By default Kubernetes sets the Job history limits so that only the last three successful and last failed jobs are retained so this list will only contain the most recent three of four jobs:
In order to stop the CronJob and clean up the Jobs associated with it you must delete the CronJob.
The output should look like the example:
All the Jobs were removed.
When you have completed your lab, click End Lab. Google Cloud Skills Boost removes the resources you’ve used and cleans the account for you.
You will be given an opportunity to rate the lab experience. Select the applicable number of stars, type a comment, and then click Submit.
The number of stars indicates the following:
You can close the dialog box if you don't want to provide feedback.
For feedback, suggestions, or corrections, please use the Support tab.
Copyright 2022 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.
This content is not currently available
We will notify you via email when it becomes available
Great!
We will contact you via email if it becomes available
One lab at a time
Confirm to end all existing labs and start this one