< img height="1" width="1" style="display:none;" alt="" src="https://px.ads.linkedin.com/collect/?pid=3131724&fmt=gif" />

Create Jobs

This section explains how to create jobs.

Prerequisites

You should join a project and have the Application Workload Management permission within the project. For more information, refer to "Project Members" and "Project Roles".

Steps

Please refer to Parameter Description for configuring job parameters.

  1. Log in to the KubeSphere web console with a user who has the Application Workload Management permission, and access your project.

  2. Click Application Workloads > Jobs in the left navigation pane.

  3. On the Jobs page, click either Jobs or CronJobs to open the list of jobs.

  4. Click Create on the page.

  5. On the Basic Information tab, configure the basic information of the job, as well as the scheduling strategy for a CronJob. Then click Next.

  6. On the Strategy Settings tab, configure the strategy for a one-time job, and then click Next.

  7. On the Pod Settings tab, set restart policies and containers for the pods managed by the job. Then click Next.

  8. On the Storage Settings tab, mount volumes for the containers managed by the job. Then click Next.

  9. On the Advanced Settings tab, specify nodes for the pods managed by the job, and set metadata for the job. Then click Create.

    Once the job is created, it will be displayed in the job list.

Parameter Description

The following explains how to configure parameters for the job.

  • Basic Information

    Parameter Description

    Name

    The name of the job. The name can only contain lowercase letters, numbers, and hyphens (-). It must start and end with a lowercase letter or number, with a maximum length of 63 characters.

    Alias

    The alias of the job. Aliases can be the same for different jobs. The alias can only contain Chinese characters, letters, numbers, and hyphens (-). It must not start or end with a hyphen (-), with a maximum length of 63 characters.

    Project

    The project to which the job belongs. It is recommended to choose a user project, as system projects are typically used for managing system resources.

    Description

    The description of the job. The description can contain any characters, with a maximum length of 256 characters.

    Schedule

    The CRON expression specifying the runtime cycle for a CronJob. KubeSphere defaults to UTC time, and you may need to adjust it based on your time zone. Available only for CronJobs.

    Maximum Startup Delay

    The maximum delay before starting a job when it fails to start according to the schedule. Available only for CronJobs.

    Successful Jobs Retention

    The number of successful jobs allowed to be retained, with a default value of 3. Each time a CronJob runs, it creates a job, and you can specify the number of jobs to retain as a historical record. Available only for CronJobs.

    Failed Jobs Retention

    The number of failed jobs allowed to be retained, with a default value of 1. Each time a CronJob runs, it creates a job, and you can specify the number of jobs to retain as a historical record. Available only for CronJobs.

    Concurrency Policy

    The policy the system adopts when multiple jobs created by a CronJob overlap. Available only for CronJobs. It includes the following policies:

    • Run jobs concurrently: New and old jobs run concurrently.

    • Skip new job: Do not run new jobs.

    • Skip old job: Immediately terminates old jobs and then runs new jobs.

  • Strategy Settings

    Configure the strategy for each job.

    Parameter Description

    Maximum Retries

    The maximum number of times the pods in the job can be restarted. If the maximum retries is reached but the job completion conditions are still not met, the job will be marked as failed.

    Complete Pods

    The number of completed pods required to mark the job as completed.

    Parallel Pods

    The number of pods that run in parallel in the job.

    Maximum Duration

    The maximum running time for the job, in seconds. If the maximum duration is reached but the job completion conditions are still not met, the job will be terminated and marked as failed.

  • Pod Settings > Restart Policy

    Select the policy the system adopts when a container in the pod fails to run.

    Parameter Description

    Re-create pod

    The system will recreate the entire pod.

    Restart container

    The system will restart the container.

  • Pod Settings > Add Container

    Create containers to run within the pod. You can create multiple containers within a pod.

    • Click Add Container to create a container.

    • Hover over a created container, then click pen on the right to edit the container settings.

    • Hover over a created container, then click trash-light on the right to delete the container.

  • Pod Settings > Add Container > Container Settings

    Configure the container’s image, name, type, and resources.

    Parameter Description

    Image

    The image required to create the container.

    • Enter the image name (e.g., nginx:latest) or path (e.g., docker.io/nginx:latest), then press Enter to search for the image.

    • If you only enter the image name, the image will be pulled from Docker Hub by default. To use a private image registry, you need to create a Secret containing the information for the private image registry, and then select the private image registry on the left side of the Image text box.

    • Click template to browse images in the current image registry.

    Container Name

    The name of the container. The name can only contain lowercase letters, numbers, and hyphens (-). It must start and end with a lowercase letter or number, with a maximum length of 63 characters.

    Container Type

    The type of container.

    • Init Container: A container that performs initialization tasks for the working containers. The working containers will only start after all init containers have successfully completed. If an init container fails, the system sets the status of the pod to failure.

    • Work Container: A container that runs the application. It is generally recommended to have only one work container running in each pod.

    CPU Request

    Reserved CPU resources for a container, measured in cores.

    CPU Limit

    Upper limit of CPU resources that a container is allowed to use, measured in cores.

    Memory Request

    Reserved memory resources for a container, measured in MiB.

    Memory Limit

    Upper limit of memory resources that a container is allowed to use, measured in MiB.

    GPU Type

    The GPU type that containers in the project can use. Currently, only NVIDIA GPU is supported.

    GPU Limit

    Upper limit on the number of GPUs that a container is allowed to use, measured in GPUs.

  • Pod Settings > Add Container > Port Settings

    Configure the ports for the container. Click Use Default Port of Images to set the container ports to the default ports of the image. Click Add Port to set multiple ports for the container.

    Parameter Description

    Protocol

    The protocol that the application in the container actually listens to. To use the Application Governance features provided by KubeSphere, ensure that the selected protocol matches the protocol that the application in the container actually listens to.

    Name

    The name of the port. To use the Application Governance features provided by KubeSphere, use the lowercase protocol name as a prefix for the port name (e.g., http-).

    Container Port

    The port number that the application in the container actually listens to.

  • Pod Settings > Add Container > Image Pull Policy

    Set whether to pull images from the image registry when creating or updating Pods.

    Parameter Description

    Use Local Image First

    When creating or updating a pod, prioritize using the images stored by the container runtime on the node.

    Pull Image Always

    When creating or updating a pod, pull the image from the image registry every time.

    Use Local Image Only

    When creating or updating a pod, only use the images stored by the container runtime on the node. If the required image is not available locally, the pod may be created with an exception.

  • Pod Settings > Add Container > Health Check

    Check the health status of the container. Before using this feature, you need to configure the application within the container to return the results of the health check.

    KubeSphere supports the following types of health check:

    Parameter Description

    Liveness Check

    Checks if the container is alive. If the liveness check fails, the system will attempt to restart the container.

    Readiness Check

    Checks if the container is ready to process requests. If the readiness check fails, the system will prevent access to the pod through a service.

    Startup Check

    Checks if the container has started. If the startup check fails, the system will disable other probes for the container and attempt to restart it.

    KubeSphere supports the following check methods:

    Parameter Description

    HTTP Request

    Sends an HTTP GET request to the virtual IP address of the pod. If the response status code is 2XX or 3XX, the check is considered successful.

    Command

    Runs a command in the container. The check is considered successful if the command’s exit code is 0.

    TCP Port

    Attempts to establish a TCP connection with the specified container port. The check is considered successful if the connection is established.

  • Pod Settings > Add Container > Health Check > Add Probe

    Create probes for liveness, readiness, or startup checks on the container.

    • Click Add Probe to create a probe.

    • Hover over the created probe, then click pen on the right to edit the probe settings.

    • Hover over the created probe, then click trash-light on the right to delete the probe.

    Parameter Description

    Path

    The protocol (HTTP or HTTPS), the path relative to the virtual IP address of the pod for HTTP requests, and the port number for the request. Only available when the health check method is HTTP Request.

    Command

    The command to run in the container. You can use commas (,) to separate the commands and its parameters. Only available when the health check method is Command.

    Port

    The container port number for TCP checks. Only available when the health check method is TCP Port.

    Initial Delay

    The delay time in seconds before the probe is initiated after container startup.

    Timeout

    The timeout period for the probe in seconds. After the timeout, the check will be considered a failure. The value must be an integer, with a minimum of 0.

    Check Interval

    The time interval for performing checks in seconds. The value must be an integer, with a minimum of 1.

    Success Threshold

    The minimum consecutive successes required to consider the check successful after a failure. The minimum value is 1. For liveness probes and startup probes, this parameter must be 1.

    Failure Threshold

    The minimum consecutive failures required to consider the check failed after a success. The minimum value is 1.

  • Pod Settings > Add Container > Lifecycle Management

    Configure actions to be performed after the container starts or before it terminates for environment checking or graceful termination. Before using this feature, you need to configure the application within the container to return the results of the performed action.

    Parameter Description

    Post-start Action

    The action to be performed after the container starts. If the post-start action fails, the system will attempt to restart the container.

    Pre-stop Action

    The action to be performed before the container terminates. This action follows these rules:

    • If the pre-stop action fails, the system will terminate the container immediately.

    • The default period for the graceful termination of a container is 30 seconds. If the pres-stop action is still running when the grace period ends, the system will provide a one-time grace period of 2 seconds.

    • After the grace period ends, regardless of whether the pres-stop action has finished, the system will terminate the container.

    KubeSphere supports the following execution methods for post-start actions and pre-stop actions:

    Parameter Description

    HTTP Request

    Sends an HTTP GET request to the virtual IP address of the pod. If the response status code is 2XX or 3XX, the action is considered successful.

    Command

    Runs a command in the container. The action is considered successful if the command’s exit code is 0.

    TCP Port

    Attempts to establish a TCP connection with the specified container port. The action is considered successful if the connection is established.

  • Pod Settings > Add Container > Lifecycle Management > Add Action

    Create post-start or pre-termination actions for the container.

    • Click Add Action to create an action.

    • Hover over the created action, then click pen on the right to edit the action settings.

    • Hover over the created action, then click trash-light on the right to delete the action.

    Parameter Description

    Path

    The protocol (HTTP or HTTPS), the path relative to the virtual IP address of the pod for HTTP requests, and the port number for the request. Only available when the action execution method is HTTP Request.

    Command

    The command to run in the container. You can use commas (,) to separate the commands and its parameters. Only available when the action execution method is Command.

    Port

    The container port number for TCP checks. Only available when the action execution method is TCP Port.

  • Pod Settings > Add Container > Start Command

    Configure the command to be executed inside the container when it starts.

    Parameter Description

    Command

    The startup command to be executed.

    Parameters

    The parameters of the startup command. Use commas to separate multiple parameters.

  • Pod Settings > Add Container > Environment Variables

    Configure environment variables for the container.

    • Click Add Environment Variable to set multiple environment variables.

    • Click Batch Reference to create environment variables using data from a ConfigMap or Secret. The ConfigMap or Secret to be referenced must belong to the same project as the container. The values of environment variables will not dynamically change with changes made in the ConfigMap or Secret after the container is created.

    • Click trash-light on the right of the created environment variable to delete it.

    Parameter Description

    Key

    The name of the environment variable.

    Value

    The value of the environment variable.

    Resource

    The name of the ConfigMap or Secret. Only available when referencing a ConfigMap or Secret.

    Key in Resource

    The key in the ConfigMap or Secret. The value corresponding to this key will be used as the value of the environment variable. Only available when referencing a ConfigMap or Secret.

  • Pod Settings > Add Container > Container Security Context

    Configure the permissions of the container process in the Linux system.

    Parameter Description

    Access Control

    Access permissions for the container process.

    • Privileged Mode: Run the container process as the root user on the host.

    • Allow Privilege Escalation: Allow the container process to gain more privileges than the parent process. This option is enabled by default when Privileged Mode is enabled.

    • Root Directory Read-Only: Set the root directory of the container filesystem to read-only.

    User and User Group

    The users and user groups running the entry point of container processes.

    • Run as Non-root: Checks if the container will run as the root user before starting. If the container is set to run as the root user, it won’t start. When this feature is enabled, the system will ignore the Privileged mode setting.

    • User: The UID (User ID) executing the container process entry point. Defaults to the UID specified in the image metadata.

    • User Group: The GID (Group ID) executing the container process entry point. Defaults to the default GID of the container runtime.

    SELinux Context

    The SELinux labels for the container process, including Level, Role, Type, and User. For more information, refer to the SELinux Documentation.

    Capabilities

    Additional capabilities added to or removed from the container process in the Linux system. Refer to the Linux Documentation for the list of Linux process capabilities.

    • When adding or removing capabilities for the container process, you need to remove the CAP_ prefix from the capability names. For example, entering SYS_TIME in the Drop text box will remove the CAP_SYS_TIME capability from the container process.

    • Click Add to set multiple instructions for adding or removing capabilities.

  • Pod Settings > Add Container > Synchronize Host Timezone

    Select the checkbox on the left of Synchronize Host Timezone will synchronize the timezone between the container and the host.

  • Storage Settings

    Mount volumes, ConfigMaps, or Secrets for the container.

    Parameter Description

    Mount Volume

    Mount Persistent Volumes, temporary volumes, or HostPath volumes to the container.

    Mount ConfigMap or Secret

    Mount data from ConfigMaps or Secrets as a volume to the container.

    • Hover over the added volume, then click pen on the right to edit the volume settings.

    • Hover over the mounted volume, then click trash-light on the right to delete the volume.

  • Storage Settings > Mount Volume > Persistent Volume

    Mount a Persistent Volume for the container. The Persistent Volume Claim used to create the Persistent Volume must belong to the project where the container is located.

    Parameter Description

    Select Persistent Volume Claim

    Select the Persistent Volume Claim used to create the Persistent Volume. This Persistent Volume Claim must belong to the project where the container is located. If there is no available Persistent Volume Claim in the project of the container, you need to create one in advance.

    Mount Mode

    The mount mode of the volume on the container.

    • Read and write: Allows the container to read from and write to the volume.

    • Read-only: Only allows the container to read from the volume.

    • Not mounted: The volume is not mounted to the container.

    Mount Path

    The path where the volume is mounted to the container. Click textfield to set the subpath that needs to be mounted. If no subpath is set, the entire volume is mounted by default.

  • Storage Settings > Mount Volume > Temporary Volume

    Mount a temporary volume for the container. Temporary volumes have the following characteristics:

    • Automatically created by the system in the storage system of the node where the pod is located.

    • Managed automatically by the system, with a capacity limit equal to the storage capacity of the node.

    • Cannot store persistent data; the system creates and deletes temporary volumes automatically when the pod is created or deleted.

    Parameter Description

    Volume Name

    The name of the temporary volume.

    Mount Mode

    The mount mode of the volume on the container.

    • Read and write: Allows the container to read from and write to the volume.

    • Read-only: Only allows the container to read from the volume.

    • Not mounted: The volume is not mounted to the container.

    Mount Path

    The path where the volume is mounted to the container. Click textfield to set the subpath that needs to be mounted. If no subpath is set, the entire volume is mounted by default.

  • Storage Settings > Mount Volume > HostPath Volume

    Mount a file or directory on the node where the pod is located to the container using a HostPath volume.

    • Files or folders under the same path on different nodes may differ, so pod replicas on different nodes may read different data from the HostPath volume.

    • Ensure that the mounted path exists on the node where the pod is located, and the container process has the necessary permissions. Otherwise, the container process will be unable to read from or write to the data in the HostPath volume.

    Parameter Description

    Volume Name

    The name of the HostPath volume.

    Host Path

    The path to the file or folder on the node that needs to be mounted.

    Mount Mode

    The mount mode of the volume on the container.

    • Read and write: Allows the container to read from and write to the volume.

    • Read-only: Only allows the container to read from the volume.

    • Not mounted: The volume is not mounted to the container.

    Mount Path

    The path where the volume is mounted to the container. Click textfield to set the subpath that needs to be mounted. If no subpath is set, the entire volume is mounted by default.

  • Storage Settings > Mount ConfigMap or Secret

    Mount data from ConfigMaps or Secrets as a volume to the container.

    Parameter Description

    Select Configmap/Select Secret

    Select the ConfigMap or Secret in the current project.

    Mount Mode

    Set the mount mode of the data from the ConfigMap or Secret on the container. Configmaps and Secrets only support mounting in Read-only mode or Not mounted.

    Mount Path

    Set the path where the data from the ConfigMap or Secret is mounted on the container.

    • The system will generate a folder based on the data from the ConfigMap or Secret and map each key-value pair to a file. Each file is named after the key, and the content is the value.

    • Click textfield to specify key-value pairs from the ConfigMap or Secret as files to be mounted. If no subpath is set, the entire ConfigMap or Secret is mounted by default. If a subpath is used, files mounted to the container will not dynamically update with changes in the ConfigMap or Secret.

    Select Specific Keys

    Mount key-value pairs from the ConfigMap or Secret as files to the container. Files mounted to the container will dynamically update with changes in the ConfigMap or Secret. Click Add to mount multiple key-value pairs.

    • Key: The key of the key-value pair in the ConfigMap or Secret to be mounted.

    • Path: The path relative to the Mount Path in the container. The specified key-value pair from the ConfigMap or Secret will be mounted to this path, and existing files in the Mount Path will be overwritten.

  • Advanced Settings

    Specify nodes for the pods managed by the job and set metadata for the job.

    Parameter Description

    Select Nodes

    Schedule pod replicas to nodes with specified labels.

    • You can manually enter key-value pairs for the labels of the target node, or click Specify Node to choose a node.

    • Click Add Node Selector to set multiple labels; pod replicas will be scheduled to nodes with all specified labels.

    • Click trash-light on the right of a created label to delete it.

    Add Metadata

    Configure labels and annotations for the job.

    • Click Add to set multiple labels or annotations.

    • Click trash-light on the right of a created label or annotation to delete it.

Receive the latest news, articles and updates from KubeSphere


Thanks for the feedback. If you have a specific question about how to use KubeSphere, ask it on Slack. Open an issue in the GitHub repo if you want to report a problem or suggest an improvement.

What’s on this Page