- [Instructor] Jobs are a construct that run a pod once
and then stop.
However, unlike pods and deployments, the output of the job
is kept around until you decide to remove it.
In this example, I'm showing you simplejob.yaml,
we have the template, and we have a spec.
In the spec, we have containers, it's just a busybox image
that is running a loop from nine through one
and just echoing it out at the end.
So, let's go ahead and run this guy.
Kubectl create -f simplejob.yaml.
It says the job was created, so let's introspect.
Kubectl get jobs.
Notice that the finalcountdown job
has one of one completion, duration two seconds
and age of seven seconds,
so if we do kubectl get pods, for example,
we'll notice that we have the finalcountdown pod
with some metadata over there.
It's not in a ready state,
but the Status of that was completed.
We can actually even take a look at the logs for this.
So we can do kubectl logs and then the pod name,
and you'll notice that we get the output
from nine through one, just like what we had in the code.
Now, let's take a look at crons.
So crons are like jobs, however, they can run periodically.
So, I have a cron here, it's called cronjob.yaml.
It's still similar to what we had before,
all it's doing here is putting out the date
and then echoing "Hello from your kubernetes cluster".
Restart policy: OnFailure and--
So this also has a schedule,
in this case it runs every minute.
So let's go ahead and run this,
kubectl create -f cronjob.yaml.
So let's look at the job for this.
We can do get cronjob, and in the example here
we're seeing hellocron, on the schedule, Suspend as false.
This just means that don't ever suspend it,
just always keep running it.
It's not active right now and it hadn't been scheduled yet,
so let's look at it again.
So there's Active one, last scheduled nine seconds ago,
age of 29 seconds.
And in fact if you even look at the jobs for this,
you'll notice that hellocron actually ran for three seconds
about 23 seconds ago.
So if you wait a little bit and then try again,
let's see, kubectl get jobs.
Here we notice that it's been a little over a minute
and a second hellocron just ran.
If you look at the cronjob as well,
nothing active right now, last scheduled for 32 seconds ago,
and the same Suspend status, false.
One thing that comes up a lot with cronjobs specifically
is how do you pause it or stop this.
So clearing my screen,
actually do a quick kubectl get cronjobs.
The name of that was hellocron,
so we can actually go ahead and edit this.
Kubectl edit cronjobs/hellocron.
This is the actual cronjob, and later down here,
you'll notice that the Suspend status is false,
so I'm going to actually change this to true, exit out,
and if I look at the cronjob again,
we'll notice that the Suspend status is true.
And then I'm going to give this a little bit of time
and then I'm going to check again to see
when the last scheduled was.
Typically we have to send a one-minute schedule,
so if we wait a little bit over a minute
we'll start to notice that the last scheduled
would've happened one minute and 23 seconds ago, et cetera,
so something over 60 is what we're looking for.
All right, let's try it out.
Notice that the last scheduled was still 82 seconds ago
and Suspend is still true.
And if we get a look at the jobs as well,
we still have the age of the last one that actually ran
was 92 seconds ago.
So that's how you stop a cronjob.