Update command outputs to k8s 1.13 based (#12771)

* Update command outputs to k8s 1.13 based

* Update command outputs to k8s 1.13 based (2)

* Add the way to download the example manifest and change datetime in a pod log

* create a job from remote url

* Update content/en/docs/tasks/job/automated-tasks-with-cron-jobs.md

Co-Authored-By: makocchi-git <makocchi@gmail.com>
pull/13136/head
makocchi 2019-03-13 02:24:42 +09:00 committed by Kubernetes Prow Robot
parent 9e471e389c
commit 23dacbb83b
1 changed files with 38 additions and 14 deletions

View File

@ -47,13 +47,14 @@ This example cron job config `.spec` file prints the current time and a hello me
{{< codenew file="application/job/cronjob.yaml" >}}
Run the example cron job by downloading the example file and then running this command:
Run the example CronJob by using this command:
```shell
kubectl create -f ./cronjob.yaml
kubectl create -f https://k8s.io/examples/application/job/cronjob.yaml
```
```
cronjob "hello" created
cronjob.batch/hello created
```
Alternatively, you can use `kubectl run` to create a cron job without writing a full config:
@ -61,8 +62,9 @@ Alternatively, you can use `kubectl run` to create a cron job without writing a
```shell
kubectl run hello --schedule="*/1 * * * *" --restart=OnFailure --image=busybox -- /bin/sh -c "date; echo Hello from the Kubernetes cluster"
```
```
cronjob "hello" created
cronjob.batch/hello created
```
After creating the cron job, get its status using this command:
@ -70,9 +72,10 @@ After creating the cron job, get its status using this command:
```shell
kubectl get cronjob hello
```
```
NAME SCHEDULE SUSPEND ACTIVE LAST-SCHEDULE
hello */1 * * * * False 0 <none>
NAME SCHEDULE SUSPEND ACTIVE LAST SCHEDULE AGE
hello */1 * * * * False 0 <none> 10s
```
As you can see from the results of the command, the cron job has not scheduled or run any jobs yet.
@ -81,9 +84,12 @@ Watch for the job to be created in around one minute:
```shell
kubectl get jobs --watch
```
```
NAME DESIRED SUCCESSFUL AGE
hello-4111706356 1 1 2s
NAME COMPLETIONS DURATION AGE
hello-4111706356 0/1 0s
hello-4111706356 0/1 0s 0s
hello-4111706356 1/1 5s 5s
```
Now you've seen one running job scheduled by the "hello" cron job.
@ -92,32 +98,49 @@ You can stop watching the job and view the cron job again to see that it schedul
```shell
kubectl get cronjob hello
```
```
NAME SCHEDULE SUSPEND ACTIVE LAST-SCHEDULE
hello */1 * * * * False 0 Mon, 29 Aug 2016 14:34:00 -0700
NAME SCHEDULE SUSPEND ACTIVE LAST SCHEDULE AGE
hello */1 * * * * False 0 50s 75s
```
You should see that the cron job "hello" successfully scheduled a job at the time specified in `LAST-SCHEDULE`.
You should see that the cron job "hello" successfully scheduled a job at the time specified in `LAST SCHEDULE`.
There are currently 0 active jobs, meaning that the job has completed or failed.
Now, find the pods that the last scheduled job created and view the standard output of one of the pods.
Note that the job name and pod name are different.
{{< note >}}
The job name and pod name are different.
{{< /note >}}
```shell
# Replace "hello-4111706356" with the job name in your system
pods=$(kubectl get pods --selector=job-name=hello-4111706356 --output=jsonpath={.items..metadata.name})
```
Check pod name:
```shell
echo $pods
```
The output is similar to this:
```
hello-4111706356-o9qcm
```
Show pod log:
```shell
kubectl logs $pods
```
The output is similar to this:
```
Mon Aug 29 21:34:09 UTC 2016
Fri Feb 22 11:02:09 UTC 2019
Hello from the Kubernetes cluster
```
@ -128,8 +151,9 @@ When you don't need a cron job any more, delete it with `kubectl delete cronjob`
```shell
kubectl delete cronjob hello
```
```
cronjob "hello" deleted
cronjob.batch "hello" deleted
```
Deleting the cron job removes all the jobs and pods it created and stops it from creating additional jobs.