Updated on 2024-11-21 GMT+08:00

Managing Workloads and Jobs

Scenario

After a workload is created, you can upgrade, monitor, roll back, or delete the workload, as well as edit its YAML file.
Table 1 Workload/Job management

Operation

Description

View Log

You can view the logs of workloads.

Upgrade

You can replace images or image tags to quickly upgrade Deployments and StatefulSets without interrupting services.

Edit YAML

You can modify and download the YAML files of Deployments, StatefulSets, CronJobs, and pods on the CCE console. YAML files of Jobs can only be viewed, copied, and downloaded.

NOTE:

If an existing CronJob is modified, the new configuration will only be applied for the new pods, and existing pods continue to run without any change.

Roll Back

Only Deployments can be rolled back.

Redeploy

You can redeploy a workload. After the workload is redeployed, all pods in the workload will be restarted.

Enable/Disable Upgrade

Only Deployments support this operation.

Manage Label

Labels are attached to workloads as key-value pairs to manage and select workloads. Jobs and Cron Jobs do not support this operation.

Delete

You can delete a workload or job that is no longer needed. Deleted workloads or jobs cannot be recovered.

View Events

You can view event names, event types, number of occurrences, Kubernetes events, first occurrence time, and last occurrence time.

Stop/Start

You can only start or stop a cron job.

Viewing Logs

You can view logs of Deployments, StatefulSets, and jobs. This section uses a Deployment as an example to describe how to view logs.

Before viewing logs, ensure that the time of the browser is the same as that on the backend server.

  1. Log in to the CCE console, go to an existing cluster, and choose Workloads in the navigation pane.
  2. Click the Deployments tab and click the View Log of the target workload.

    On the displayed View Log window, you can view logs.

    Figure 1 Viewing logs of a workload

Upgrading a Workload

You quickly upgrade Deployments and StatefulSets on the console.

This section uses a Deployment as an example to describe how to upgrade a workload.

Before replacing an image or image version, upload the new image to the SWR service. For details, see Uploading an Image Through a Container Engine Client.

  1. Log in to the CCE console and click the cluster name to access the cluster console. In the navigation pane on the left, choose Workloads.
  2. Click the Deployments tab. Locate the target workload and click Upgrade in the Operation column.

    • Workloads cannot be upgraded in batches.
    • Before performing an in-place StatefulSet upgrade, you must manually delete old pods. Otherwise, the upgrade status is always displayed as Processing.

  3. Upgrade the workload based on service requirements. The method for setting parameter is the same as that for creating a workload.
  4. After the update is complete, click Upgrade Workload, manually confirm the YAML file, and submit the upgrade.

Editing a YAML file

You can modify and download the YAML files of Deployments, StatefulSets, CronJobs, and pods on the CCE console. YAML files of Jobs can only be viewed, copied, and downloaded. This section uses a Deployment as an example to describe how to edit the YAML file.

  1. Log in to the CCE console and click the cluster name to access the cluster console. In the navigation pane on the left, choose Workloads.
  2. Click the Deployments tab. Locate the target workload and choose More > Edit YAML in the Operation column. In the dialog box that is displayed, modify the YAML file.
  3. Click OK.
  4. (Optional) In the Edit YAML window, click Download to download the YAML file.

Rolling Back a Workload (Available Only for Deployments)

CCE records the release history of all Deployments. You can roll back a Deployment to a specified version.

  1. Log in to the CCE console and click the cluster name to access the cluster console. In the navigation pane on the left, choose Workloads.
  2. Click the Deployments tab. Locate the target workload and choose More > Roll Back in the Operation column.
  3. Switch to the Change History tab. Locate the target workload and click Roll Back to This Version. Manually confirm the YAML file and click OK.

    Figure 2 Rolling back a workload version

Redeploying a Workload

After you redeploy a workload, all pods in the workload will be restarted. This section uses Deployments as an example to illustrate how to redeploy a workload.

  1. Log in to the CCE console and click the cluster name to access the cluster console. In the navigation pane on the left, choose Workloads.
  2. Click the Deployments tab. Locate the target workload and choose More > Redeploy in the Operation column.
  3. In the dialog box that is displayed, click Yes.

Disabling/Enabling Upgrade (Available Only for Deployments)

Only Deployments support this operation.

  • After the upgrade is disabled, the upgrade command can be delivered but will not be applied to the pods.

    If you are performing a rolling upgrade, the rolling upgrade stops after the disabling upgrade command is delivered. In this case, the new and old pods co-exist.

  • If a Deployment is being upgraded, it can be upgraded or rolled back. Its pods will inherit the latest updates of the Deployment. If they are inconsistent, the pods are upgraded automatically according to the latest information of the Deployment.

The workload cannot be rolled back when the upgrade is disabled.

  1. Log in to the CCE console and click the cluster name to access the cluster console. In the navigation pane on the left, choose Workloads.
  2. Click the Deployments tab. Locate the target workload and choose More > Disable/Enable Upgrade in the Operation column.
  3. In the dialog box that is displayed, click Yes.

Managing Labels

Labels are key-value pairs and can be attached to workloads. You can manage and select workloads by labels. You can add labels to multiple workloads or a specified workload.

  1. Log in to the CCE console and click the cluster name to access the cluster console. In the navigation pane on the left, choose Workloads.
  2. Click the Deployments tab and choose More > Manage Label in the Operation column of the workload.
  3. Click Add, enter a key and a value, and click OK.

    Figure 3 Managing labels

    A key-value pair must contain 1 to 63 characters starting and ending with a letter or digit. Only letters, digits, hyphens (-), underscores (_), and periods (.) are allowed.

Deleting a Workload/Job

You can delete a workload or job that is no longer needed. Deleted workloads or jobs cannot be recovered. This section uses a Deployment as an example to describe how to delete a workload.

  1. Log in to the CCE console and click the cluster name to access the cluster console. In the navigation pane on the left, choose Workloads.
  2. Locate the workload you will delete and choose More > Delete in the Operation column.

    Read the prompts carefully. A workload cannot be recovered after it is deleted.

  3. Click Yes.

    • If the node where the pod is located is unavailable or shut down and the workload cannot be deleted, you can forcibly delete the pod from the pod list on the workload details page.
    • Ensure that the storage volumes to be deleted are not used by other workloads. If these volumes are imported or have snapshots, you can only unbind them.

Events

This section uses Deployments as an example to illustrate how to view events of a workload. To view the event of a job or CronJob, click View Event in the Operation column of the target workload.

  1. Log in to the CCE console and click the cluster name to access the cluster console. In the navigation pane on the left, choose Workloads.
  2. On the Deployments tab, click the target workload. In the Pods tab, click the View Events to view the event name, event type, number of occurrences, Kubernetes event, first occurrence time, and last occurrence time.

    Event data will be retained for one hour and then automatically deleted.