From 39ea02c887f6ea8d3c0b1aa05894b8d3c28e35c9 Mon Sep 17 00:00:00 2001 From: Mihnea Spirescu Date: Mon, 20 Apr 2020 21:01:34 +0100 Subject: [PATCH] Lab 3 - changed content --- .../jobs-initcontainers-cronjobs/cronjob.md | 13 +++++------- .../initcontainer.md | 15 +++++++------- .../jobs-initcontainers-cronjobs/intro.md | 10 +++++----- .../jobs-parallels.md | 12 +++++------ .../jobs-initcontainers-cronjobs/jobs.md | 20 +++++++++---------- 5 files changed, 33 insertions(+), 37 deletions(-) diff --git a/kubernetes/jobs-initcontainers-cronjobs/cronjob.md b/kubernetes/jobs-initcontainers-cronjobs/cronjob.md index 19eb9a0..f00c2bf 100644 --- a/kubernetes/jobs-initcontainers-cronjobs/cronjob.md +++ b/kubernetes/jobs-initcontainers-cronjobs/cronjob.md @@ -1,10 +1,8 @@ -[Cron Job resources](https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/) run a job periodically on a given schedule, written in a `Cron` format. - -They are useful for creating periodic and recurring tasks, e.g running backups or sending emails. +Written in a `Cron` format, a [Cron Job resource](https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/) runs a job periodically on a given schedule. These are useful for creating periodic and recurring tasks, e.g running backups or sending emails. ## Create Hello Cron Job -Look at the file `cronjob.yaml`{{open}}. This example create a job every minute which prints the current time and a hello message. +Take a look at the file `cronjob.yaml`{{open}}. This example create a job every minute which prints the current time and a hello message. `kubectl apply -f /manifests/cronjob.yaml`{{execute}} @@ -14,15 +12,14 @@ Check the status of the cronjob: `kubectl get cronjob hello`{{execute}} -After creating the cron job you can see, by looking at `LAST-SCHEDULE` column, that it hasn't been scheduled yet: +Immediatly after creating a cron job, the `LAST-SCHEDULE` column will have no value (``). This indicates that the CronJob hasn't run yet. ` master $ kubectl get cronjob hello NAME SCHEDULE SUSPEND ACTIVE LAST SCHEDULE AGE hello */1 * * * * False 0 8s ` - -Watch the job until `LAST-SCHEDULE` column get a value, it means it began to run: +Once the `LAST-SCHEDULE` column gets a value, it indicates that the CronJobs is now scheduled to run: `kubectl get cronjob --watch`{{execute}} @@ -32,7 +29,7 @@ Check the cron job again, you should see that the cronjob has been scheduled at ### Cron Job Logs -In order to see the job's logs, we need to know the pod created: +In order to see the job's logs, we need to know the pod's name: `kubectl get pod -o 'jsonpath={.items[0].metadata.name}'; echo`{{execute}} diff --git a/kubernetes/jobs-initcontainers-cronjobs/initcontainer.md b/kubernetes/jobs-initcontainers-cronjobs/initcontainer.md index fc55e47..fa2e5b9 100644 --- a/kubernetes/jobs-initcontainers-cronjobs/initcontainer.md +++ b/kubernetes/jobs-initcontainers-cronjobs/initcontainer.md @@ -1,26 +1,25 @@ -[Init Container](https://kubernetes.io/docs/concepts/workloads/pods/init-containers/) is a container which is executed before the app container is started. `Init-containers` are usually used for deploying utilities or execute scripts which are not presented in the app image and it needs to run. +An [Init Container](https://kubernetes.io/docs/concepts/workloads/pods/init-containers/) is a container which is executed before the application container is started. `Init-containers` are usually used for deploying utilities or execute scripts which are not loaded and executed in the application container image. ## Create a Pod with an init container -Look at the file `init-container.yaml`{{open}}. +Take a look at the file `init-container.yaml`{{open}}. -This example runs an `init-container` which creates a helloworld file in a volume and an application pod will be scheduled if the helloworld file exist in a specific path and it can read it. +This example runs an `init-container` which creates a `helloworld` file in a volume. The application pod will be scheduled if the `helloworld` file exist at a specific path and the pod can access it. Create the init container: `kubectl apply -f /manifests/init-container.yaml`{{execute}} -It could get some time until the init container finish successfully and the pod run. +It could take some time until the Init container finishes the execution successfully and the application container is scheduled to run. ### Pod status -Init container get some time until it creates the file so you could have to check the status of the pod couple of times: +The Init container will take some time until it creates the file so you might have to check the status of the pod a couple of times: `kubectl get pods`{{execute}} -If the pod is running means that the file was created and the pod can read it. - -We are going to check manually that the file is there with the correct content: +If the pod is running, it means that the file was created succesfully and the pod can read it. +We are going to manually check that the file is at the specified path and it has the correct content: `kubectl exec -ti happypanda -- cat /opt/workdir/helloworld `{{execute}} diff --git a/kubernetes/jobs-initcontainers-cronjobs/intro.md b/kubernetes/jobs-initcontainers-cronjobs/intro.md index c645343..a82f574 100644 --- a/kubernetes/jobs-initcontainers-cronjobs/intro.md +++ b/kubernetes/jobs-initcontainers-cronjobs/intro.md @@ -1,9 +1,9 @@ -This scenario provides an overview of Jobs, Init Containers and Cron Jobs in Kubernetes. +This scenario provides an overview of Jobs, Init Containers and CronJobs in Kubernetes. [Jobs resources](https://kubernetes.io/docs/concepts/workloads/controllers/jobs-run-to-completion/) create one or more pods and ensures that all of them successfully terminate. -There're two types of jobs: +There are two types of jobs: * **Non-parallel Job:** A Job which creates only one Pod (which is re-created if the Pod terminates unsuccessfully), and which is completed when the Pod terminates successfully. * **Parallel jobs with a completion count:** A Job that is completed when a certain number of Pods terminate successfully. You specify the desired number of completions using the completions field. @@ -13,7 +13,7 @@ There're two types of jobs: [Init Containers](https://kubernetes.io/docs/concepts/workloads/pods/init-containers/) are regular containers within a pod that run before the app container and they also satisfy the following statements: * They can run setup scripts not present in an app container - e.g prepopulate some data, waiting until a specific service is up and running and etc. -* A pod can have one or more init containers apart of app containers -* They always run to completation +* A pod can have one or more init containers apart from app containers +* Init containers always run to completation * Each one must complete successfully before the next one is started -* Application container won't run if any init container won't finish successfully +* The application container won't run if any of the configured init containers will not finish the execution successfully diff --git a/kubernetes/jobs-initcontainers-cronjobs/jobs-parallels.md b/kubernetes/jobs-initcontainers-cronjobs/jobs-parallels.md index 91f7fd1..0d1384a 100644 --- a/kubernetes/jobs-initcontainers-cronjobs/jobs-parallels.md +++ b/kubernetes/jobs-initcontainers-cronjobs/jobs-parallels.md @@ -1,10 +1,10 @@ -To create a parallel job we can use ` spec.parallelism` to set how many pods we want to run in parallel and `spec.completions` to set how many job's completition we would like to achieve. +To create a parallel job we can use `spec.parallelism` to set how many pods we want to run in parallel and `spec.completions` to set how many job completitions we would like to achieve. ## Create Countdown Parallel Job -Look at the file `jobs-parallels.yaml`{{open}}. +Inspect the file `jobs-parallels.yaml`{{open}}. -This is the same `countdown` job then the previous scenario but we have added `spec.parallelism` and `spec.completions`. +This is the same `countdown` job we used in the previous scenario but we have added `spec.parallelism` and `spec.completions` parameters. The job will run 2 pods in parallel until it reaches 8 completions successfully. @@ -14,18 +14,18 @@ Create countdown parallel job: ### Job status -Await for a few seconds to get the 8 completions and then check the status of the job: +Wait for a few seconds to get the 8 completions and then check the status of the job: `kubectl get jobs`{{execute}} -You should see a result like the following if not, wait for a few seconds and check again: +You should see a similar result to the following, but if not, wait for a few more seconds and check again: ` NAME DESIRED SUCCESSFUL AGE countdown 8 8 16s ` -This job was executed successfully 8 time by keeping 2 jobs running in parallel. +This job was executed successfully 8 time by running 2 jobs in parallel. ### Job Logs diff --git a/kubernetes/jobs-initcontainers-cronjobs/jobs.md b/kubernetes/jobs-initcontainers-cronjobs/jobs.md index 6c2cdc5..0ead512 100644 --- a/kubernetes/jobs-initcontainers-cronjobs/jobs.md +++ b/kubernetes/jobs-initcontainers-cronjobs/jobs.md @@ -1,21 +1,21 @@ -[Jobs resources](https://kubernetes.io/docs/concepts/workloads/controllers/jobs-run-to-completion/) are used to running a batch job, supporting parallel jobs until reach a specific number of completions. +[Job resources](https://kubernetes.io/docs/concepts/workloads/controllers/jobs-run-to-completion/) are used to facilitate the execution of a batch job. Through Job resources, Kubernetes also supports parallel jobs which will finish executing when a specific number of successful completions is reached. -Therefore with Jobs, we can run a work items such as frames to be rendered, files to be transcoded, ranges of keys in a NoSQL database to scan, and so on. +Therefore with Job resources, we can run work items such as frames to be rendered, files to be transcoded, ranges of keys in a NoSQL database to scan, and so on. -Take a look at [Jobs Api reference](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.11/#job-v1-batch) to see how to build a job resource in Kubernetes. +Have a look at [Jobs Api reference](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.18/#job-v1-batch) to see how to build a job resource in Kubernetes. -Pods created by jobs are not deleted. Keeping them around allows you to still view the logs of completed pods to check for errors. If you want to remove them, you need to do that manually. +Pods created by jobs are not automatically deleted. Keeping the pods around allows you to view the logs of completed jobs in order to check for potential errors. If you want to remove them, you need to do that manually. ## Create Countdown Job -Look at the file `job.yaml`{{open}}. +Take a look at the file `job.yaml`{{open}}. -This example creates a job which runs a bash command to countdown from 10 to 1. +This example creates a job which runs a bash command to count down from 10 to 1. -Notice that the field `spec.restartPolicy` just allow two values: "OnFailure" or "Never", for further information read [here](https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#example-states) +Notice that the field `spec.restartPolicy` allow only two values: "OnFailure" or "Never". For further information read [here](https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#example-states) -> **Note:** There're situations where you want to fail a job after some ammount of retries, to do so use `spec.backoffLimit`. It is set by default to 6. -> You could want to manage the duration of the job, not matter how many Pods are created. You can use `spec.activeDeadlineSeconds` and once a Job reaches this value(in sec), the Job and all of its Pods are terminates. +> **Note:** There are situations where you want to fail a job after a number of retries. To do so, use `spec.backoffLimit` which, by defauly, is set 6. +> You can use `spec.activeDeadlineSeconds` to limit the execution time in case you want to manage the duration of a specific job. If the execution reaches this deadline, the Job and all of its Pods are terminated. Create the countdown job: @@ -29,7 +29,7 @@ Check the status of the job: ### Job Logs -In order to see the job's logs we need to get the job name: +In order to see the job's logs we need to get the name of the Job in question: `kubectl get pods -o 'jsonpath={.items[0].metadata.name}'; echo`{{execute}}