You can use a Job to create an application in the Container Service for Kubernetes (ACK) console. This topic describes how to use a Job to create a busybox application and the operations that you can perform on the application.

Prerequisites

An ACK cluster is created. For more information, see Create an ACK dedicated cluster.

Background information

A Job processes multiple short-lived, one-off tasks at a time to ensure that one or more pods in the tasks terminate with success.

Kubernetes supports the following types of Jobs:

  • Non-parallel Jobs: In most cases, a Job of this type starts only one pod unless the pod fails. The Job is considered complete when the pod terminates with success.
  • Jobs with a fixed completion count: A non-zero positive value is specified for .spec.completions. A Job of this type starts pods one after one. The Job is considered complete when the number of pods that terminate with success is equal to the value of .spec.completions.
  • Parallel Jobs with a work queue: A non-zero positive value is specified for .spec.Parallelism. A Job of this type starts multiple pods at a time. The Job is considered complete when all pods terminate and at least one pod terminates with success. .spec.completions is not required.
  • Parallel Jobs with a fixed completion count: A Job of this type has both .spec.completions and .spec.Parallelism specified. The Job starts multiple pods at a time to process a work queue.
Jobs can manage pods based on the settings of .spec.completions and .spec.Parallelism as described in the following table.
Note The Job created in this example is a parallel Job with a fixed completion count.
Job type Example Action completions Parallelism
One-off Job Database migration The Job starts only one pod. The Job is complete when the pod terminates with success. 1 1
Job with a fixed completion count Start pods one after one to process a work queue The Job starts pods one after one. The Job is complete when the number of pods that terminate with success reaches the value of .spec.completions. 2+ 1
Parallel Job with a fixed completion count Start multiple pods at a time to process a work queue The Job starts multiple pods at a time. The Job is complete when the number of pods that terminate with success reaches the value of .spec.completions. 2+ 2+
Parallel Job Start multiple pods at a time to process a work queue The Job starts one or more pods at a time. The Job is complete when at least one pod terminates with success. 1 2+

Procedure

  1. Log on to the ACK console.
  2. In the left-side navigation pane of the ACK console, click Clusters.
  3. On the Clusters page, find the cluster that you want to manage and click the name of the cluster or click Details in the Actions column. The details page of the cluster appears.
  4. In the left-side navigation pane of the details page, choose Workloads > Jobs.
  5. On the Jobs page, click Create from Image in the upper-right corner.
    • Name: Enter a name for the application.
    • Type: Select Job from the drop-down list.
      Note In this example, Job is selected for Type.
    • Label: Add a label to the application. The label is used to identify the application.
    • Annotations: Add an annotation to the application.
    • Synchronize Timezone: Specify whether to synchronize the time zone between nodes and containers.
    Create
  6. Configure containers.
    Note You can configure a pod that contains one or more containers for the application.
    1. Set basic parameters.
      • Image Name: Select an image.
        • You can click Select Image. In the dialog box that appears, select an image and click OK. In this example, an NGINX image is selected. On the Search tab, select Docker Images from the drop-down list, enter NGINX in the search box, and then click Search.
          • Images from Container Registry: On the Alibaba Cloud Container Registry tab, you can select an image that is hosted by Container Registry. You must select the region and the Container Registry instance to which the image belongs. For more information about Container Registry, see What is Container Registry?.
            Note On the Alibaba Cloud Container Registry tab, you can search for images by name.
          • Docker official images: On the Docker Official Images tab, you can select a Docker image.
          • Favorite images: On the Favorite Images tab, you can select a Docker image that you have added to your favorite list.
          • Search for images: On the Search tab, you can select Alibaba Cloud Image from the drop-down list and specify a region to search for an image in Container Registry. You can also select Docker Images from the drop-down list and search for a Docker image.
        • You can also enter the address of a private registry. The registry address must be in the following format: domainname/namespace/imagename:tag.
      • Image Version:
        • Click Select Image Version and select an image version. If you do not specify an image version, the latest image version is used.
        • You can select the following image pull policies:
          • ifNotPresent: If the image that you want to pull is found on your on-premises machine, the image on your on-premises machine is used. Otherwise, ACK pulls the image from the corresponding repository.
          • Always: ACK pulls the image from Container Registry each time the application is deployed or scaled out.
          • Never: ACK uses only images on your on-premises machine.
          Note If you select Image Pull Policy, no image pull policy is applied.
        • To pull the image without a password, click Set Image Pull Secret to set a Secret that is used to pull the image. For more information, see Use the aliyun-acr-credential-helper component to pull images without a password.
      • Always: If you do not select this option, ACK caches the pulled image. This improves the efficiency deploying applications. If the specified image version is the same as the cached image version, ACK deploys the application from the cached image. Therefore, when you update the application code, if you do not change the image version for reasons such as to support the upper-layer workloads, the previously cached image is used. After you select the Always option, Container Service always pulls the latest image from the repository. This ensures that the latest image and code are used to deploy the application.
      • Set Image Pull Secret: If you use a private image, we recommend that you configure a Secret to secure the image. For more information, see Create an application by using an image pull Secret.
      • Resource Limit: You can specify an upper limit for the CPU and memory resources that the application can consume. This prevents the application from occupying an excessive amount of resources. CPU resources are measured in millicores. Each millicore is one thousandth of one core. Memory resources are measured in bytes, which can be GiB, MiB, or KiB.
      • Required Resources: The amount of CPU and memory resources that are reserved for the application. These resources are exclusive to the container. This prevents the application from becoming unavailable when other services or processes occupy these resources.
      • Container Start Parameter: Select stdin to send the input from the ACK console to the container. Select tty to send start parameters that are defined in a virtual terminal to the console.
      • Privileged Container: If you select Privileged Container, privileged=true is set for the container. This indicates that the privilege mode is enabled. If you do not select Privileged Container, privileged=false is set for the container and the privilege mode is disabled.
      • Init Container: If you select this check box, an init container is created. Init containers contain practical tools. For more information, see Init Container.
      • Port: Set the host port and container port. TCP and UDP are supported.
      Basic container parameters
    2. Optional:# Specify environment variables.

      You can configure environment variables in key-value pairs for pods. Environment variables are used to apply pod configurations to containers. For more information, see Pod variables.

    3. Optional:Configure the lifecycle of the container.

      You can set the following parameters to configure the lifecycle of the container: Start, Post Start, and Pre Stop. For more information, see Attach Handlers to Container Lifecycle Events.

      • Start: Set the command and parameter that take effect before the container starts.
      • Post Start: Set the command that takes effect after the container starts.
      • Pre Stop: Set the command that takes effect before the container stops.
      Lifecycle management
    4. Optional:Configure volumes.

      Local storage and cloud storage are supported.

      • Add Local Storage: supports hostPath, ConfigMap, Secret, and emptyDir. The specified volume is mounted to a path in the container. For more information, see Volumes.
      • Add PVC: supports disks, Apsara File Storage NAS (NAS) file systems, and Object Storage Service (OSS) buckets.
    5. Optional:Configure Log Service. You can customize log collection configurations and add custom tags to the collected log data.
      Note Make sure that the Log Service agent is installed in the cluster.

      You can configure the following log collection settings:

      • Logstore: Create a Logstore in Log Service to store the collected log data.
      • Log Path in Container: Specify stdout or a container path to collect log data.
        • stdout: specifies that stdout is collected.
        • A container path: specifies that the log files in the specified path of the container are collected. Wildcard characters can be used in the path.

      You can also add custom tags. Custom tags are added to the log content when the log is collected. Log data with tags is easier to aggregate and filter.

  7. After you complete the basic configuration, click Next.
  8. Configure advanced settings.

    You can set parameters in the Job Settings section.

    Parameter Description
    Completions The number of pods that must terminate with success. Default value: 1.
    Parallelism The number of pods that the Job must run in parallel. Default value: 1.
    Timeout The activeDeadlineSeconds field in the YAML file. This field specifies the duration time limit of the Job. If the Job is not complete within the duration time limit, the system attempts to terminate the Job.
    BackoffLimit The maximum number of attempts to recreate pods after pods fail. Default value: 6. Failed pods are recreated with an exponential back-off delay. The upper limit of the delay is 6 minutes.
    Restart Valid values: Never and On Failure.
    Advanced settings
  9. Click Create.
  10. After the application is deployed, you are redirected to the Complete wizard page. The resource objects of the application are displayed.
    Created

    You can click View Details to view application details.

    You can view the status of pods in the Status column. In this example, two pods are created to run in parallel based on the Job configuration.

    Wait until all pods are created.

  11. Click the Back icon in the upper-left corner of the page. On the Jobs page, you can view the time when the Job is complete.
    Note If the pods associated with the Job are not complete, the end time is not displayed.

What to do next

In the left-side navigation pane of the ACK console, click Clusters to go to the Clusters page. Find the cluster that you want to manage, and click the cluster name or click Details in the Actions column. On the details page of the cluster, click Workloads. Click the Jobs tab. Find the application that you want to manage, and click the application name or click Details in the Actions column. On the application details page, you can scale and refresh the application. You can also view the YAML file of the application.

  • Scale: In the upper-right corner of the application details page, click Scale to scale the application to a required number of pods.
  • View the YAML file: In the upper-right corner of the application details page, click View in YAML. Then, you can update and download the YAML file. You can also save the YAML file as a template.
  • Refresh: In the upper-right corner of the application details page, click Refresh to refresh the page.