Running a fleet
Follow these steps to run a fleet with the CLI or with the console. Note that fleets run as soon as they are created, so that running a fleet and creating a fleet are the same operation.
Before you begin
To successfully run a fleet, make sure you have followed the steps in Preparing to run your fleet. You also have the option to use Code Engine to build the image you reference when you create your fleet.
Running a fleet by using the CLI
Use the following example command to run a fleet. This command allows additional options. For a complete list of all available command options, see the CLI docs.
ibmcloud ce fleet run --name my-fleet --image icr.io/codeengine/helloworld --subnetpool-name my-pool --tasks-state-store mytaskstore --tasks 1
--name- The name of the fleet. This value must be unique across all fleets within the same project. If no fleet name is specified, a random one is generated.
--image- The name of the container image that is used to process the tasks. This value is required.
--subnetpool-name- The name of the subnet pool to use for the fleet network placement.
--tasks-state-store- Specify the persistent data store that stores the state of the tasks of the fleet. This value is required.
--tasks- The number of tasks to run.
Example output.
Successfully created fleet with name 'my-fleet' and ID '1a1a1a1a-2b2b-3c3c-4d4d-5e5e5e5e5e5e'
Run 'ibmcloud ce fleet get --fleet-id 1a1a1a1a-2b2b-3c3c-4d4d-5e5e5e5e5e5e' to check the fleet status.
Run 'ibmcloud ce fleet worker list --fleet-id 1a1a1a1a-2b2b-3c3c-4d4d-5e5e5e5e5e5e' to retrieve a list of provisioned workers.
Run 'ibmcloud ce fleet task list --fleet-id 1a1a1a1a-2b2b-3c3c-4d4d-5e5e5e5e5e5e' to retrieve a list of tasks.
OK
Running a fleet by using the console
Follow these steps to run a fleet in the Code Engine console.
- Open the Code Engine console.
- Click Start Creating.
- Select a project from the list of available projects. You can also create a new one. You must have a selected project to run a fleet.
- Select the option to create a fleet.
- Specify a name for the fleet. Make sure the name is unique across all fleets within the project.
- Specify a container image for your fleet, for example,
icr.io/codeengine/helloworld. If you have your own source code that you want to turn into a container image, see Planning your build. For more information about the code that is used for this example, see helloworld. - Follow the prompts to configure your fleet.
- In the Tasks section, configure the task specification method for the fleet. For more information, see Task specification.
- In the Resources and scaling section, configure your instance resources and specify how your instances scale up or down.
- In the Network placement section, review the subnets that your worker nodes deploy on.
- In the Environmental variables and Volume mounts sections, add optional key-value pairs, configmaps, or additional files that can be used by your running code.
- Click create.
Task specification
Fleets always have at least one task, but can have a much larger number. You can specify the number of tasks to complete, the number of tasks and instances to run at a time, and the order in which tasks are completed. When you run your fleet, worker nodes automatically scale up based on the number of tasks to be completed.
You can specify tasks in the following ways.
- Number of tasks: To run a specific number of tasks, you can specify any positive integer. In the CLI, use the
--tasksoption. In the UI, select Number of tasks and enter the number you want to run. - Task index: To specify a range of tasks, you can specify a task index that includes a comma separated list of ranges and positive integers, such as
2-5,7-8,10. In the CLI, use the--task-indexesoption. In the UI, select Task indexes and enter the range. - Task file: To have different tasks run with different commands or arguments, you can create a task specification file that overrides the image definition. This file should be formatted in JSON. In the CLI, specify the file
with the
OPTIONoption. In the UI, select Tasks from file and specify the file name. See an example of lines that can be added to a task specification file below.
Example lines in a task specification file.
{ "cmds": ["my", "multipart", "command"], "args": ["arg1", "arg2"]}
{ "cmds": ["other", "cmd"], "args": ["arg"]}
{ "args": ["argA", "argB", "argC"]}
{ "cmds": ["just", "another", "command"]}
Deleting a fleet by using the CLI
A fleet is not deleted automatically when it reaches its final state. Since there is a quota limit of 1000 fleets per project (see Project quotas), delete the fleet using the CLI when you do not need it anymore.
Use the following example command to delete a fleet. This command allows additional options. For a complete list of all available command options, see the CLI docs.
ibmcloud ce fleet delete --force --fleet-id 1a1a1a1a-2b2b-3c3c-4d4d-5e5e5e5e5e5e
Deleting a fleet by using the console
A fleet is not deleted automatically when it reaches its final state. Since there is a quota limit of 1000 fleets per project (see Project quotas), delete the fleet using the CLI when you do not need it anymore.
Follow these steps to delete a fleet in the console.
- Go to the Fleets page:
- Select your project from the Projects page in the Code Engine console.
- Click Fleets to see a list of existing fleets.
- Go to the row with the fleet that you want to remove and click the delete (trash can) icon.
- Confirm the deletion when prompted.